11package txnbuild
22
33import (
4+ "github.com/stellar/go/ingest/sac"
5+ "github.com/stellar/go/strkey"
46 "github.com/stellar/go/support/errors"
57 "github.com/stellar/go/xdr"
68)
@@ -10,6 +12,77 @@ type RestoreFootprint struct {
1012 Ext xdr.TransactionExt
1113}
1214
15+ var defaultAssetBalanceRestorationFees = SorobanFees {
16+ Instructions : 0 ,
17+ ReadBytes : 500 ,
18+ WriteBytes : 500 ,
19+ ResourceFee : 4_000_000 ,
20+ }
21+
22+ // AssetBalanceRestorationParams configures the restore footprint operation returned by
23+ // NewAssetBalanceRestoration
24+ type AssetBalanceRestorationParams struct {
25+ // NetworkPassphrase is the passphrase for the Stellar network
26+ NetworkPassphrase string
27+ // Contract is the contract which holds the asset balance
28+ Contract string
29+ // Asset is the asset which is held in the balance
30+ Asset Asset
31+ // SourceAccount is the source account for the restoration operation
32+ SourceAccount string
33+ // Fees configures the fee values for the
34+ // soroban transaction. If this field is omitted
35+ // default fee values will be used
36+ Fees SorobanFees
37+ }
38+
39+ // NewAssetBalanceRestoration constructs a restore footprint operation which restores an
40+ // asset balance for a smart contract
41+ func NewAssetBalanceRestoration (params AssetBalanceRestorationParams ) (RestoreFootprint , error ) {
42+ asset , err := params .Asset .ToXDR ()
43+ if err != nil {
44+ return RestoreFootprint {}, err
45+ }
46+
47+ var assetContractID xdr.Hash
48+ assetContractID , err = asset .ContractID (params .NetworkPassphrase )
49+ if err != nil {
50+ return RestoreFootprint {}, err
51+ }
52+
53+ decoded , err := strkey .Decode (strkey .VersionByteContract , params .Contract )
54+ if err != nil {
55+ return RestoreFootprint {}, err
56+ }
57+ var contractID xdr.Hash
58+ copy (contractID [:], decoded )
59+
60+ resources := params .Fees
61+ if resources .ResourceFee == 0 {
62+ resources = defaultAssetBalanceRestorationFees
63+ }
64+
65+ return RestoreFootprint {
66+ SourceAccount : params .SourceAccount ,
67+ Ext : xdr.TransactionExt {
68+ V : 1 ,
69+ SorobanData : & xdr.SorobanTransactionData {
70+ Resources : xdr.SorobanResources {
71+ Footprint : xdr.LedgerFootprint {
72+ ReadWrite : []xdr.LedgerKey {
73+ sac .ContractBalanceLedgerKey (assetContractID , contractID ),
74+ },
75+ },
76+ Instructions : xdr .Uint32 (resources .Instructions ),
77+ ReadBytes : xdr .Uint32 (resources .ReadBytes ),
78+ WriteBytes : xdr .Uint32 (resources .WriteBytes ),
79+ },
80+ ResourceFee : xdr .Int64 (resources .ResourceFee ),
81+ },
82+ },
83+ }, nil
84+ }
85+
1386func (f * RestoreFootprint ) BuildXDR () (xdr.Operation , error ) {
1487 xdrOp := xdr.RestoreFootprintOp {
1588 Ext : xdr.ExtensionPoint {
0 commit comments