Skip to content

Commit 10df201

Browse files
authored
5551/xdrill operations (#5604)
1 parent 2e64bc5 commit 10df201

31 files changed

+3883
-0
lines changed

Diff for: ingest/ledger_transaction.go

+144
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,147 @@ func (t *LedgerTransaction) NewMaxFee() (uint32, bool) {
615615
func (t *LedgerTransaction) Successful() bool {
616616
return t.Result.Successful()
617617
}
618+
619+
func (t *LedgerTransaction) GetTransactionV1Envelope() (xdr.TransactionV1Envelope, bool) {
620+
switch t.Envelope.Type {
621+
case xdr.EnvelopeTypeEnvelopeTypeTx:
622+
switch t.Envelope.Type {
623+
case 2:
624+
return *t.Envelope.V1, true
625+
default:
626+
return xdr.TransactionV1Envelope{}, false
627+
}
628+
case xdr.EnvelopeTypeEnvelopeTypeTxFeeBump:
629+
return t.Envelope.MustFeeBump().Tx.InnerTx.MustV1(), true
630+
default:
631+
return xdr.TransactionV1Envelope{}, false
632+
}
633+
}
634+
635+
func (t *LedgerTransaction) LedgerKeyHashesFromSorobanFootprint() []string {
636+
var ledgerKeyHash []string
637+
638+
v1Envelope, ok := t.GetTransactionV1Envelope()
639+
if !ok {
640+
return ledgerKeyHash
641+
}
642+
643+
for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadOnly {
644+
ledgerKeyBase64, err := xdr.MarshalBase64(ledgerKey)
645+
if err != nil {
646+
panic(err)
647+
}
648+
if ledgerKeyBase64 != "" {
649+
ledgerKeyHash = append(ledgerKeyHash, ledgerKeyBase64)
650+
}
651+
}
652+
653+
for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadWrite {
654+
ledgerKeyBase64, err := xdr.MarshalBase64(ledgerKey)
655+
if err != nil {
656+
panic(err)
657+
}
658+
if ledgerKeyBase64 != "" {
659+
ledgerKeyHash = append(ledgerKeyHash, ledgerKeyBase64)
660+
}
661+
}
662+
663+
return ledgerKeyHash
664+
}
665+
666+
func (t *LedgerTransaction) ContractCodeHashFromSorobanFootprint() (string, bool) {
667+
v1Envelope, ok := t.GetTransactionV1Envelope()
668+
if !ok {
669+
return "", false
670+
}
671+
for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadOnly {
672+
contractCode, ok := t.contractCodeFromContractData(ledgerKey)
673+
if !ok {
674+
return "", false
675+
}
676+
if contractCode != "" {
677+
return contractCode, true
678+
}
679+
}
680+
681+
for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadWrite {
682+
contractCode, ok := t.contractCodeFromContractData(ledgerKey)
683+
if !ok {
684+
return "", false
685+
}
686+
if contractCode != "" {
687+
return contractCode, true
688+
}
689+
}
690+
691+
return "", true
692+
}
693+
694+
func (t *LedgerTransaction) contractCodeFromContractData(ledgerKey xdr.LedgerKey) (string, bool) {
695+
contractCode, ok := ledgerKey.GetContractCode()
696+
if !ok {
697+
return "", false
698+
}
699+
700+
codeHash, err := xdr.MarshalBase64(contractCode.Hash)
701+
if err != nil {
702+
panic(err)
703+
}
704+
705+
return codeHash, true
706+
}
707+
708+
func (t *LedgerTransaction) ContractIdFromTxEnvelope() (string, bool) {
709+
v1Envelope, ok := t.GetTransactionV1Envelope()
710+
if !ok {
711+
return "", false
712+
}
713+
for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadWrite {
714+
contractId, ok := t.contractIdFromContractData(ledgerKey)
715+
if !ok {
716+
return "", false
717+
}
718+
719+
if contractId != "" {
720+
return contractId, true
721+
}
722+
}
723+
724+
for _, ledgerKey := range v1Envelope.Tx.Ext.SorobanData.Resources.Footprint.ReadOnly {
725+
contractId, ok := t.contractIdFromContractData(ledgerKey)
726+
if !ok {
727+
return "", false
728+
}
729+
730+
if contractId != "" {
731+
return contractId, true
732+
}
733+
}
734+
735+
return "", true
736+
}
737+
738+
func (t *LedgerTransaction) contractIdFromContractData(ledgerKey xdr.LedgerKey) (string, bool) {
739+
contractData, ok := ledgerKey.GetContractData()
740+
if !ok {
741+
return "", false
742+
}
743+
contractIdHash, ok := contractData.Contract.GetContractId()
744+
if !ok {
745+
return "", false
746+
}
747+
748+
var contractIdByte []byte
749+
var contractId string
750+
var err error
751+
contractIdByte, err = contractIdHash.MarshalBinary()
752+
if err != nil {
753+
panic(err)
754+
}
755+
contractId, err = strkey.Encode(strkey.VersionByteContract, contractIdByte)
756+
if err != nil {
757+
panic(err)
758+
}
759+
760+
return contractId, true
761+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package operation
2+
3+
import "fmt"
4+
5+
type AccountMergeDetail struct {
6+
Account string `json:"account"`
7+
AccountMuxed string `json:"account_muxed"`
8+
AccountMuxedID uint64 `json:"account_muxed_id,string"`
9+
Into string `json:"into"`
10+
IntoMuxed string `json:"into_muxed"`
11+
IntoMuxedID uint64 `json:"into_muxed_id,string"`
12+
}
13+
14+
func (o *LedgerOperation) AccountMergeDetails() (AccountMergeDetail, error) {
15+
destinationAccount, ok := o.Operation.Body.GetDestination()
16+
if !ok {
17+
return AccountMergeDetail{}, fmt.Errorf("could not access Destination info for this operation (index %d)", o.OperationIndex)
18+
}
19+
20+
accountMergeDetail := AccountMergeDetail{
21+
Account: o.SourceAccount(),
22+
Into: destinationAccount.Address(),
23+
}
24+
25+
var err error
26+
var accountMuxed string
27+
var accountMuxedID uint64
28+
accountMuxed, accountMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR())
29+
if err != nil {
30+
return AccountMergeDetail{}, err
31+
}
32+
33+
accountMergeDetail.AccountMuxed = accountMuxed
34+
accountMergeDetail.AccountMuxedID = accountMuxedID
35+
36+
var intoMuxed string
37+
var intoMuxedID uint64
38+
intoMuxed, intoMuxedID, err = getMuxedAccountDetails(destinationAccount)
39+
if err != nil {
40+
return AccountMergeDetail{}, err
41+
}
42+
43+
accountMergeDetail.IntoMuxed = intoMuxed
44+
accountMergeDetail.IntoMuxedID = intoMuxedID
45+
46+
return accountMergeDetail, nil
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package operation
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/stellar/go/xdr"
7+
)
8+
9+
type AllowTrustDetail struct {
10+
AssetCode string `json:"asset_code"`
11+
AssetIssuer string `json:"asset_issuer"`
12+
AssetType string `json:"asset_type"`
13+
Trustor string `json:"trustor"`
14+
Trustee string `json:"trustee"`
15+
TrusteeMuxed string `json:"trustee_muxed"`
16+
TrusteeMuxedID uint64 `json:"trustee_muxed_id,string"`
17+
Authorize bool `json:"authorize"`
18+
AuthorizeToMaintainLiabilities bool `json:"authorize_to_maintain_liabilities"`
19+
ClawbackEnabled bool `json:"clawback_enabled"`
20+
}
21+
22+
func (o *LedgerOperation) AllowTrustDetails() (AllowTrustDetail, error) {
23+
op, ok := o.Operation.Body.GetAllowTrustOp()
24+
if !ok {
25+
return AllowTrustDetail{}, fmt.Errorf("could not access AllowTrust info for this operation (index %d)", o.OperationIndex)
26+
}
27+
28+
allowTrustDetail := AllowTrustDetail{
29+
Trustor: op.Trustor.Address(),
30+
Trustee: o.SourceAccount(),
31+
Authorize: xdr.TrustLineFlags(op.Authorize).IsAuthorized(),
32+
AuthorizeToMaintainLiabilities: xdr.TrustLineFlags(op.Authorize).IsAuthorizedToMaintainLiabilitiesFlag(),
33+
ClawbackEnabled: xdr.TrustLineFlags(op.Authorize).IsClawbackEnabledFlag(),
34+
}
35+
36+
var err error
37+
var assetCode, assetIssuer, assetType string
38+
err = op.Asset.ToAsset(o.sourceAccountXDR().ToAccountId()).Extract(&assetType, &assetCode, &assetIssuer)
39+
if err != nil {
40+
return AllowTrustDetail{}, err
41+
}
42+
43+
allowTrustDetail.AssetCode = assetCode
44+
allowTrustDetail.AssetIssuer = assetIssuer
45+
allowTrustDetail.AssetType = assetType
46+
47+
var trusteeMuxed string
48+
var trusteeMuxedID uint64
49+
trusteeMuxed, trusteeMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR())
50+
if err != nil {
51+
return AllowTrustDetail{}, err
52+
}
53+
54+
allowTrustDetail.TrusteeMuxed = trusteeMuxed
55+
allowTrustDetail.TrusteeMuxedID = trusteeMuxedID
56+
57+
return allowTrustDetail, nil
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package operation
2+
3+
import "fmt"
4+
5+
type BeginSponsoringFutureReservesDetail struct {
6+
SponsoredID string `json:"sponsored_id"`
7+
}
8+
9+
func (o *LedgerOperation) BeginSponsoringFutureReservesDetails() (BeginSponsoringFutureReservesDetail, error) {
10+
op, ok := o.Operation.Body.GetBeginSponsoringFutureReservesOp()
11+
if !ok {
12+
return BeginSponsoringFutureReservesDetail{}, fmt.Errorf("could not access BeginSponsoringFutureReserves info for this operation (index %d)", o.OperationIndex)
13+
}
14+
15+
return BeginSponsoringFutureReservesDetail{
16+
SponsoredID: op.SponsoredId.Address(),
17+
}, nil
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package operation
2+
3+
import "fmt"
4+
5+
type BumpSequenceDetails struct {
6+
BumpTo int64 `json:"bump_to,string"`
7+
}
8+
9+
func (o *LedgerOperation) BumpSequenceDetails() (BumpSequenceDetails, error) {
10+
op, ok := o.Operation.Body.GetBumpSequenceOp()
11+
if !ok {
12+
return BumpSequenceDetails{}, fmt.Errorf("could not access BumpSequence info for this operation (index %d)", o.OperationIndex)
13+
}
14+
15+
return BumpSequenceDetails{
16+
BumpTo: int64(op.BumpTo),
17+
}, nil
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package operation
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/stellar/go/xdr"
7+
)
8+
9+
type ChangeTrustDetail struct {
10+
AssetCode string `json:"asset_code"`
11+
AssetIssuer string `json:"asset_issuer"`
12+
AssetType string `json:"asset_type"`
13+
LiquidityPoolID string `json:"liquidity_pool_id"`
14+
Limit int64 `json:"limit,string"`
15+
Trustee string `json:"trustee"`
16+
Trustor string `json:"trustor"`
17+
TrustorMuxed string `json:"trustor_muxed"`
18+
TrustorMuxedID uint64 `json:"trustor_muxed_id,string"`
19+
}
20+
21+
func (o *LedgerOperation) ChangeTrustDetails() (ChangeTrustDetail, error) {
22+
op, ok := o.Operation.Body.GetChangeTrustOp()
23+
if !ok {
24+
return ChangeTrustDetail{}, fmt.Errorf("could not access GetChangeTrust info for this operation (index %d)", o.OperationIndex)
25+
}
26+
27+
var err error
28+
changeTrustDetail := ChangeTrustDetail{
29+
Trustor: o.SourceAccount(),
30+
Limit: int64(op.Limit),
31+
}
32+
33+
if op.Line.Type == xdr.AssetTypeAssetTypePoolShare {
34+
changeTrustDetail.AssetType, changeTrustDetail.LiquidityPoolID, err = getLiquidityPoolAssetDetails(*op.Line.LiquidityPool)
35+
if err != nil {
36+
return ChangeTrustDetail{}, err
37+
}
38+
} else {
39+
var assetCode, assetIssuer, assetType string
40+
err = op.Line.ToAsset().Extract(&assetType, &assetCode, &assetIssuer)
41+
if err != nil {
42+
return ChangeTrustDetail{}, err
43+
}
44+
45+
changeTrustDetail.AssetCode = assetCode
46+
changeTrustDetail.AssetIssuer = assetIssuer
47+
changeTrustDetail.AssetType = assetType
48+
changeTrustDetail.Trustee = assetIssuer
49+
}
50+
51+
var trustorMuxed string
52+
var trustorMuxedID uint64
53+
trustorMuxed, trustorMuxedID, err = getMuxedAccountDetails(o.sourceAccountXDR())
54+
if err != nil {
55+
return ChangeTrustDetail{}, err
56+
}
57+
58+
changeTrustDetail.TrustorMuxed = trustorMuxed
59+
changeTrustDetail.TrustorMuxedID = trustorMuxedID
60+
61+
return changeTrustDetail, nil
62+
}
63+
64+
func getLiquidityPoolAssetDetails(lpp xdr.LiquidityPoolParameters) (string, string, error) {
65+
if lpp.Type != xdr.LiquidityPoolTypeLiquidityPoolConstantProduct {
66+
return "", "", fmt.Errorf("unknown liquidity pool type %d", lpp.Type)
67+
}
68+
69+
cp := lpp.ConstantProduct
70+
71+
var err error
72+
var poolID xdr.PoolId
73+
var poolIDString string
74+
poolID, err = xdr.NewPoolId(cp.AssetA, cp.AssetB, cp.Fee)
75+
if err != nil {
76+
return "", "", err
77+
}
78+
79+
poolIDString = PoolIDToString(poolID)
80+
81+
return "liquidity_pool_shares", poolIDString, nil
82+
}

0 commit comments

Comments
 (0)