From b18b4450443e589ebd500e6b4842a68a87f71417 Mon Sep 17 00:00:00 2001 From: Simon Chow Date: Mon, 1 Jul 2024 13:15:40 -0400 Subject: [PATCH 1/2] Add nodeid and signature to ledgers --- internal/transform/ledger.go | 32 ++++++++++++++++++++++++++++++++ internal/transform/schema.go | 2 ++ 2 files changed, 34 insertions(+) diff --git a/internal/transform/ledger.go b/internal/transform/ledger.go index 9324e21e..61bfdaf1 100644 --- a/internal/transform/ledger.go +++ b/internal/transform/ledger.go @@ -1,6 +1,7 @@ package transform import ( + "encoding/hex" "fmt" "strconv" @@ -8,6 +9,7 @@ import ( "github.com/stellar/stellar-etl/internal/utils" "github.com/stellar/go/historyarchive" + "github.com/stellar/go/strkey" "github.com/stellar/go/xdr" ) @@ -64,6 +66,17 @@ func TransformLedger(inputLedger historyarchive.Ledger, lcm xdr.LedgerCloseMeta) } } + var outputNodeID string + var outputSignature string + LedgerCloseValueSignature, ok := ledgerHeader.ScpValue.Ext.GetLcValueSignature() + if ok { + outputNodeID, err = getAddress(LedgerCloseValueSignature.NodeId) + if err != nil { + return LedgerOutput{}, err + } + outputSignature = hex.EncodeToString(LedgerCloseValueSignature.Signature) + } + transformedLedger := LedgerOutput{ Sequence: outputSequence, LedgerID: outputLedgerID, @@ -83,6 +96,8 @@ func TransformLedger(inputLedger historyarchive.Ledger, lcm xdr.LedgerCloseMeta) MaxTxSetSize: outputMaxTxSetSize, ProtocolVersion: outputProtocolVersion, SorobanFeeWrite1Kb: outputSorobanFeeWrite1Kb, + NodeID: outputNodeID, + Signature: outputSignature, } return transformedLedger, nil } @@ -167,3 +182,20 @@ func getTransactionPhase(transactionPhase []xdr.TransactionPhase) (transactionEn return transactionSlice } + +// TODO: This should be moved into the go monorepo xdr functions +// Or nodeID should just be an xdr.AccountId but the error message would be incorrect +func getAddress(nodeID xdr.NodeId) (string, error) { + switch nodeID.Type { + case xdr.PublicKeyTypePublicKeyTypeEd25519: + ed, ok := nodeID.GetEd25519() + if !ok { + return "", fmt.Errorf("Could not get Ed25519") + } + raw := make([]byte, 32) + copy(raw, ed[:]) + return strkey.Encode(strkey.VersionByteAccountID, raw) + default: + return "", fmt.Errorf("Unknown node id type: %v", nodeID.Type) + } +} diff --git a/internal/transform/schema.go b/internal/transform/schema.go index 0398ef74..88ba7b85 100644 --- a/internal/transform/schema.go +++ b/internal/transform/schema.go @@ -29,6 +29,8 @@ type LedgerOutput struct { ProtocolVersion uint32 `json:"protocol_version"` LedgerID int64 `json:"id"` SorobanFeeWrite1Kb int64 `json:"soroban_fee_write_1kb"` + NodeID string `json:"node_id"` + Signature string `json:"signature"` } // TransactionOutput is a representation of a transaction that aligns with the BigQuery table history_transactions From fb4181bcbadc158f28096bc88eba22a4fd9a5da0 Mon Sep 17 00:00:00 2001 From: Simon Chow Date: Mon, 1 Jul 2024 13:32:08 -0400 Subject: [PATCH 2/2] Change to base64 --- internal/transform/ledger.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/transform/ledger.go b/internal/transform/ledger.go index 61bfdaf1..a25708a7 100644 --- a/internal/transform/ledger.go +++ b/internal/transform/ledger.go @@ -1,7 +1,7 @@ package transform import ( - "encoding/hex" + "encoding/base64" "fmt" "strconv" @@ -74,7 +74,7 @@ func TransformLedger(inputLedger historyarchive.Ledger, lcm xdr.LedgerCloseMeta) if err != nil { return LedgerOutput{}, err } - outputSignature = hex.EncodeToString(LedgerCloseValueSignature.Signature) + outputSignature = base64.StdEncoding.EncodeToString(LedgerCloseValueSignature.Signature) } transformedLedger := LedgerOutput{