github.com/stellar/stellar-etl@v1.0.1-0.20240312145900-4874b6bf2b89/internal/transform/account_signer.go (about) 1 package transform 2 3 import ( 4 "fmt" 5 "sort" 6 7 "github.com/guregu/null" 8 "github.com/stellar/go/ingest" 9 "github.com/stellar/go/xdr" 10 "github.com/stellar/stellar-etl/internal/utils" 11 ) 12 13 // TransformSigners converts account signers from the history archive ingestion system into a form suitable for BigQuery 14 func TransformSigners(ledgerChange ingest.Change, header xdr.LedgerHeaderHistoryEntry) ([]AccountSignerOutput, error) { 15 var signers []AccountSignerOutput 16 17 ledgerEntry, changeType, outputDeleted, err := utils.ExtractEntryFromChange(ledgerChange) 18 if err != nil { 19 return signers, err 20 } 21 outputLastModifiedLedger := uint32(ledgerEntry.LastModifiedLedgerSeq) 22 accountEntry, accountFound := ledgerEntry.Data.GetAccount() 23 if !accountFound { 24 return signers, fmt.Errorf("could not extract signer data from ledger entry of type: %+v", ledgerEntry.Data.Type) 25 } 26 27 closedAt, err := utils.TimePointToUTCTimeStamp(header.Header.ScpValue.CloseTime) 28 if err != nil { 29 return signers, err 30 } 31 32 ledgerSequence := header.Header.LedgerSeq 33 34 sponsors := accountEntry.SponsorPerSigner() 35 for signer, weight := range accountEntry.SignerSummary() { 36 var sponsor null.String 37 if sponsorDesc, isSponsored := sponsors[signer]; isSponsored { 38 sponsor = null.StringFrom(sponsorDesc.Address()) 39 } 40 41 signers = append(signers, AccountSignerOutput{ 42 AccountID: accountEntry.AccountId.Address(), 43 Signer: signer, 44 Weight: weight, 45 Sponsor: sponsor, 46 LastModifiedLedger: outputLastModifiedLedger, 47 LedgerEntryChange: uint32(changeType), 48 Deleted: outputDeleted, 49 ClosedAt: closedAt, 50 LedgerSequence: uint32(ledgerSequence), 51 }) 52 } 53 sort.Slice(signers, func(a, b int) bool { return signers[a].Weight < signers[b].Weight }) 54 return signers, nil 55 }