Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nodeid and signature to ledgers #260

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions internal/transform/ledger.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package transform

import (
"encoding/base64"
"fmt"
"strconv"

"github.com/stellar/stellar-etl/internal/toid"
"github.com/stellar/stellar-etl/internal/utils"

"github.com/stellar/go/historyarchive"
"github.com/stellar/go/strkey"
"github.com/stellar/go/xdr"
)

Expand Down Expand Up @@ -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 = base64.StdEncoding.EncodeToString(LedgerCloseValueSignature.Signature)
}

transformedLedger := LedgerOutput{
Sequence: outputSequence,
LedgerID: outputLedgerID,
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
}
2 changes: 2 additions & 0 deletions internal/transform/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading