github.com/stellar/stellar-etl@v1.0.1-0.20240312145900-4874b6bf2b89/internal/input/assets.go (about) 1 package input 2 3 import ( 4 "context" 5 6 "github.com/stellar/stellar-etl/internal/transform" 7 "github.com/stellar/stellar-etl/internal/utils" 8 9 "github.com/stellar/go/xdr" 10 ) 11 12 type AssetTransformInput struct { 13 Operation xdr.Operation 14 OperationIndex int32 15 TransactionIndex int32 16 LedgerSeqNum int32 17 } 18 19 // GetPaymentOperations returns a slice of payment operations that can include new assets from the ledgers in the provided range (inclusive on both ends) 20 func GetPaymentOperations(start, end uint32, limit int64, isTest bool, isFuture bool) ([]AssetTransformInput, error) { 21 env := utils.GetEnvironmentDetails(isTest, isFuture) 22 backend, err := utils.CreateBackend(start, end, env.ArchiveURLs) 23 if err != nil { 24 return []AssetTransformInput{}, err 25 } 26 27 assetSlice := []AssetTransformInput{} 28 ctx := context.Background() 29 for seq := start; seq <= end; seq++ { 30 // Get ledger from sequence number 31 ledger, err := backend.GetLedgerArchive(ctx, seq) 32 if err != nil { 33 return []AssetTransformInput{}, err 34 } 35 36 transactionSet := transform.GetTransactionSet(ledger) 37 38 for txIndex, transaction := range transactionSet { 39 for opIndex, op := range transaction.Operations() { 40 if op.Body.Type == xdr.OperationTypePayment || op.Body.Type == xdr.OperationTypeManageSellOffer { 41 assetSlice = append(assetSlice, AssetTransformInput{ 42 Operation: op, 43 OperationIndex: int32(opIndex), 44 TransactionIndex: int32(txIndex), 45 LedgerSeqNum: int32(seq), 46 }) 47 } 48 49 } 50 51 } 52 if int64(len(assetSlice)) >= limit && limit >= 0 { 53 break 54 } 55 } 56 57 return assetSlice, nil 58 }