Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a1f0f73
xdrill for ledgerCloseMeta
chowbao Jan 8, 2025
f1f97a9
go mod tidy
chowbao Jan 8, 2025
36cfcbc
Move util functions from ledger.go to utils.go
chowbao Jan 9, 2025
d064296
change some return values to pointers
chowbao Jan 9, 2025
15fe1e5
Change ledger to Ledger
chowbao Jan 9, 2025
d45b0fd
Remove Ledger struct; pass lcm as param
chowbao Jan 10, 2025
e9de99c
xdrill transaction helper functions
chowbao Jan 9, 2025
40d5057
Move xdrill ledger functions to ingest as subpackage
chowbao Jan 10, 2025
8942168
Change Ledger to use lcm as param instead
chowbao Jan 10, 2025
b5feb2c
Move xdrill ledger functions to ingest as subpackage
chowbao Jan 10, 2025
4aedfdb
Change Ledger to use lcm as param instead
chowbao Jan 10, 2025
a5bd927
Move transaction helper functions to ingest
chowbao Jan 10, 2025
0b62fe2
xdrill transaction helper functions
chowbao Jan 9, 2025
cce0cfe
Move xdrill ledger functions to ingest as subpackage
chowbao Jan 10, 2025
dab3bd9
Move transaction helper functions to ingest
chowbao Jan 10, 2025
219391d
Merge remote-tracking branch 'origin/5550/xdrill-transactions' into 5…
chowbao Jan 10, 2025
58fcfe2
fix merge issues
chowbao Jan 10, 2025
18dd712
fix merge errors
chowbao Jan 10, 2025
314b605
xdrill for operations
chowbao Jan 10, 2025
d385526
Merge branch 'master' into 5549/xdrill-ledgers
chowbao Jan 21, 2025
be020c9
address comments
chowbao Jan 21, 2025
e2ce9bd
Merge branch '5549/xdrill-ledgers' into 5550/xdrill-transactions
chowbao Jan 21, 2025
69f9bf2
Change count to uint32
chowbao Jan 21, 2025
44e627f
Merge branch '5549/xdrill-ledgers' into 5550/xdrill-transactions
chowbao Jan 21, 2025
10b4031
wip
chowbao Jan 21, 2025
93f9639
add txEnvelope OperationsCount()
chowbao Jan 21, 2025
b890631
Merge branch '5549/xdrill-ledgers' into 5550/xdrill-transactions
chowbao Jan 21, 2025
47ecec8
update timebound
chowbao Jan 21, 2025
c2a3616
add InclusionFee()
chowbao Jan 21, 2025
019a3fd
rename to InclusionFeeCharged
chowbao Jan 21, 2025
ee153f8
fix tests
chowbao Jan 21, 2025
16d94ff
Merge branch '5549/xdrill-ledgers' into 5550/xdrill-transactions
chowbao Jan 21, 2025
e9d5511
Merge branch '5550/xdrill-transactions' into 5551/xdrill-operations
chowbao Jan 21, 2025
3bc82f4
update tests
chowbao Jan 21, 2025
21dd54e
address comments
chowbao Jan 21, 2025
b6851fc
Merge branch '5549/xdrill-ledgers' into 5550/xdrill-transactions
chowbao Jan 21, 2025
3d7876c
Merge branch '5550/xdrill-transactions' into 5551/xdrill-operations
chowbao Jan 21, 2025
c68cd9a
updates from comments
chowbao Jan 23, 2025
86d5d78
Add structs for each operation
chowbao Feb 3, 2025
b7c0737
Update marshalbase64
chowbao Feb 3, 2025
a3846f2
Fix typos
chowbao Feb 3, 2025
fc6b854
fix ci/cd
chowbao Feb 3, 2025
875c995
fix tests
chowbao Feb 4, 2025
5c68c65
Update hash.go
chowbao Feb 4, 2025
cc6d49d
add string for js
chowbao Feb 6, 2025
0258c83
make createcontract better
chowbao Feb 6, 2025
52353e1
address comments
chowbao Feb 14, 2025
f73350b
Merge branch 'master' into 5551/xdrill-operations
chowbao Feb 14, 2025
44d4fb3
Merge branch 'master' into 5551/xdrill-operations
chowbao Apr 14, 2025
76c6f87
Move xdrill operations to procesors/operations
chowbao Apr 14, 2025
1c086d8
Merge branch 'master' into 5551/xdrill-operations
chowbao Apr 14, 2025
7c872df
Merge branch 'master' into 5551/xdrill-operations
chowbao Apr 17, 2025
3f92082
Address comments
chowbao Apr 17, 2025
4da1948
Merge branch 'master' into 5551/xdrill-operations
chowbao Apr 17, 2025
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
144 changes: 144 additions & 0 deletions ingest/ledger_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,147 @@ func (t *LedgerTransaction) NewMaxFee() (uint32, bool) {
func (t *LedgerTransaction) Successful() bool {
return t.Result.Successful()
}

func (t *LedgerTransaction) GetTransactionV1Envelope() (xdr.TransactionV1Envelope, bool) {
switch t.Envelope.Type {
case xdr.EnvelopeTypeEnvelopeTypeTx:
switch t.Envelope.Type {
case 2:
return *t.Envelope.V1, true
default:
return xdr.TransactionV1Envelope{}, false
}
case xdr.EnvelopeTypeEnvelopeTypeTxFeeBump:
return t.Envelope.MustFeeBump().Tx.InnerTx.MustV1(), true
default:
return xdr.TransactionV1Envelope{}, false
}
}

func (t *LedgerTransaction) LedgerKeyHashesFromSorobanFootprint() []string {
var ledgerKeyHash []string

v1Envelope, ok := t.GetTransactionV1Envelope()
if !ok {
return ledgerKeyHash
}

for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadOnly {
ledgerKeyBase64, err := xdr.MarshalBase64(ledgerKey)
if err != nil {
panic(err)
}
if ledgerKeyBase64 != "" {
ledgerKeyHash = append(ledgerKeyHash, ledgerKeyBase64)
}
}

for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadWrite {
ledgerKeyBase64, err := xdr.MarshalBase64(ledgerKey)
if err != nil {
panic(err)
}
if ledgerKeyBase64 != "" {
ledgerKeyHash = append(ledgerKeyHash, ledgerKeyBase64)
}
}

return ledgerKeyHash
}

func (t *LedgerTransaction) ContractCodeHashFromSorobanFootprint() (string, bool) {
v1Envelope, ok := t.GetTransactionV1Envelope()
if !ok {
return "", false
}
for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadOnly {
contractCode, ok := t.contractCodeFromContractData(ledgerKey)
if !ok {
return "", false
}
if contractCode != "" {
return contractCode, true
}
}

for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadWrite {
contractCode, ok := t.contractCodeFromContractData(ledgerKey)
if !ok {
return "", false
}
if contractCode != "" {
return contractCode, true
}
}

return "", true
}

func (t *LedgerTransaction) contractCodeFromContractData(ledgerKey xdr.LedgerKey) (string, bool) {
contractCode, ok := ledgerKey.GetContractCode()
if !ok {
return "", false
}

codeHash, err := xdr.MarshalBase64(contractCode.Hash)
if err != nil {
panic(err)
}

return codeHash, true
}

func (t *LedgerTransaction) ContractIdFromTxEnvelope() (string, bool) {
v1Envelope, ok := t.GetTransactionV1Envelope()
if !ok {
return "", false
}
for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadWrite {
contractId, ok := t.contractIdFromContractData(ledgerKey)
if !ok {
return "", false
}

if contractId != "" {
return contractId, true
}
}

for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadOnly {
contractId, ok := t.contractIdFromContractData(ledgerKey)
if !ok {
return "", false
}

if contractId != "" {
return contractId, true
}
}

return "", true
}

func (t *LedgerTransaction) contractIdFromContractData(ledgerKey xdr.LedgerKey) (string, bool) {
contractData, ok := ledgerKey.GetContractData()
if !ok {
return "", false
}
contractIdHash, ok := contractData.Contract.GetContractId()
if !ok {
return "", false
}

var contractIdByte []byte
var contractId string
var err error
contractIdByte, err = contractIdHash.MarshalBinary()
if err != nil {
panic(err)
}
contractId, err = strkey.Encode(strkey.VersionByteContract, contractIdByte)
if err != nil {
panic(err)
}

return contractId, true
}
47 changes: 47 additions & 0 deletions ingest/processors/operation_processor/account_merge_details.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package operation

import "fmt"

type AccountMergeDetail struct {
Account string `json:"account"`
AccountMuxed string `json:"account_muxed"`
AccountMuxedID uint64 `json:"account_muxed_id,string"`
Into string `json:"into"`
IntoMuxed string `json:"into_muxed"`
IntoMuxedID uint64 `json:"into_muxed_id,string"`
}

func (o *LedgerOperation) AccountMergeDetails() (AccountMergeDetail, error) {
destinationAccount, ok := o.Operation.Body.GetDestination()
if !ok {
return AccountMergeDetail{}, fmt.Errorf("could not access Destination info for this operation (index %d)", o.OperationIndex)
}

accountMergeDetail := AccountMergeDetail{
Account: o.SourceAccount(),
Into: destinationAccount.Address(),
}

var err error
var accountMuxed string
var accountMuxedID uint64
accountMuxed, accountMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR())
if err != nil {
return AccountMergeDetail{}, err
}

accountMergeDetail.AccountMuxed = accountMuxed
accountMergeDetail.AccountMuxedID = accountMuxedID

var intoMuxed string
var intoMuxedID uint64
intoMuxed, intoMuxedID, err = getMuxedAccountDetails(destinationAccount)
if err != nil {
return AccountMergeDetail{}, err
}

accountMergeDetail.IntoMuxed = intoMuxed
accountMergeDetail.IntoMuxedID = intoMuxedID

return accountMergeDetail, nil
}
58 changes: 58 additions & 0 deletions ingest/processors/operation_processor/allow_trust_details.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package operation

import (
"fmt"

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

type AllowTrustDetail struct {
AssetCode string `json:"asset_code"`
AssetIssuer string `json:"asset_issuer"`
AssetType string `json:"asset_type"`
Trustor string `json:"trustor"`
Trustee string `json:"trustee"`
TrusteeMuxed string `json:"trustee_muxed"`
TrusteeMuxedID uint64 `json:"trustee_muxed_id,string"`
Authorize bool `json:"authorize"`
AuthorizeToMaintainLiabilities bool `json:"authorize_to_maintain_liabilities"`
ClawbackEnabled bool `json:"clawback_enabled"`
}

func (o *LedgerOperation) AllowTrustDetails() (AllowTrustDetail, error) {
op, ok := o.Operation.Body.GetAllowTrustOp()
if !ok {
return AllowTrustDetail{}, fmt.Errorf("could not access AllowTrust info for this operation (index %d)", o.OperationIndex)
}

allowTrustDetail := AllowTrustDetail{
Trustor: op.Trustor.Address(),
Trustee: o.SourceAccount(),
Authorize: xdr.TrustLineFlags(op.Authorize).IsAuthorized(),
AuthorizeToMaintainLiabilities: xdr.TrustLineFlags(op.Authorize).IsAuthorizedToMaintainLiabilitiesFlag(),
ClawbackEnabled: xdr.TrustLineFlags(op.Authorize).IsClawbackEnabledFlag(),
}

var err error
var assetCode, assetIssuer, assetType string
err = op.Asset.ToAsset(o.sourceAccountXDR().ToAccountId()).Extract(&assetType, &assetCode, &assetIssuer)
if err != nil {
return AllowTrustDetail{}, err
}

allowTrustDetail.AssetCode = assetCode
allowTrustDetail.AssetIssuer = assetIssuer
allowTrustDetail.AssetType = assetType

var trusteeMuxed string
var trusteeMuxedID uint64
trusteeMuxed, trusteeMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR())
if err != nil {
return AllowTrustDetail{}, err
}

allowTrustDetail.TrusteeMuxed = trusteeMuxed
allowTrustDetail.TrusteeMuxedID = trusteeMuxedID

return allowTrustDetail, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package operation

import "fmt"

type BeginSponsoringFutureReservesDetail struct {
SponsoredID string `json:"sponsored_id"`
}

func (o *LedgerOperation) BeginSponsoringFutureReservesDetails() (BeginSponsoringFutureReservesDetail, error) {
op, ok := o.Operation.Body.GetBeginSponsoringFutureReservesOp()
if !ok {
return BeginSponsoringFutureReservesDetail{}, fmt.Errorf("could not access BeginSponsoringFutureReserves info for this operation (index %d)", o.OperationIndex)
}

return BeginSponsoringFutureReservesDetail{
SponsoredID: op.SponsoredId.Address(),
}, nil
}
18 changes: 18 additions & 0 deletions ingest/processors/operation_processor/bump_sequence_details.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package operation

import "fmt"

type BumpSequenceDetails struct {
BumpTo int64 `json:"bump_to,string"`
}

func (o *LedgerOperation) BumpSequenceDetails() (BumpSequenceDetails, error) {
op, ok := o.Operation.Body.GetBumpSequenceOp()
if !ok {
return BumpSequenceDetails{}, fmt.Errorf("could not access BumpSequence info for this operation (index %d)", o.OperationIndex)
}

return BumpSequenceDetails{
BumpTo: int64(op.BumpTo),
}, nil
}
82 changes: 82 additions & 0 deletions ingest/processors/operation_processor/change_trust_details.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package operation

import (
"fmt"

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

type ChangeTrustDetail struct {
AssetCode string `json:"asset_code"`
AssetIssuer string `json:"asset_issuer"`
AssetType string `json:"asset_type"`
LiquidityPoolID string `json:"liquidity_pool_id"`
Limit int64 `json:"limit,string"`
Trustee string `json:"trustee"`
Trustor string `json:"trustor"`
TrustorMuxed string `json:"trustor_muxed"`
TrustorMuxedID uint64 `json:"trustor_muxed_id,string"`
}

func (o *LedgerOperation) ChangeTrustDetails() (ChangeTrustDetail, error) {
op, ok := o.Operation.Body.GetChangeTrustOp()
if !ok {
return ChangeTrustDetail{}, fmt.Errorf("could not access GetChangeTrust info for this operation (index %d)", o.OperationIndex)
}

var err error
changeTrustDetail := ChangeTrustDetail{
Trustor: o.SourceAccount(),
Limit: int64(op.Limit),
}

if op.Line.Type == xdr.AssetTypeAssetTypePoolShare {
changeTrustDetail.AssetType, changeTrustDetail.LiquidityPoolID, err = getLiquidityPoolAssetDetails(*op.Line.LiquidityPool)
if err != nil {
return ChangeTrustDetail{}, err
}
} else {
var assetCode, assetIssuer, assetType string
err = op.Line.ToAsset().Extract(&assetType, &assetCode, &assetIssuer)
if err != nil {
return ChangeTrustDetail{}, err
}

changeTrustDetail.AssetCode = assetCode
changeTrustDetail.AssetIssuer = assetIssuer
changeTrustDetail.AssetType = assetType
changeTrustDetail.Trustee = assetIssuer
}

var trustorMuxed string
var trustorMuxedID uint64
trustorMuxed, trustorMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR())
if err != nil {
return ChangeTrustDetail{}, err
}

changeTrustDetail.TrustorMuxed = trustorMuxed
changeTrustDetail.TrustorMuxedID = trustorMuxedID

return changeTrustDetail, nil
}

func getLiquidityPoolAssetDetails(lpp xdr.LiquidityPoolParameters) (string, string, error) {
if lpp.Type != xdr.LiquidityPoolTypeLiquidityPoolConstantProduct {
return "", "", fmt.Errorf("unknown liquidity pool type %d", lpp.Type)
}

cp := lpp.ConstantProduct

var err error
var poolID xdr.PoolId
var poolIDString string
poolID, err = xdr.NewPoolId(cp.AssetA, cp.AssetB, cp.Fee)
if err != nil {
return "", "", err
}

poolIDString = PoolIDToString(poolID)

return "liquidity_pool_shares", poolIDString, nil
}
Loading
Loading