github.com/ava-labs/avalanchego@v1.11.11/wallet/chain/x/builder/builder_with_options.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package builder 5 6 import ( 7 "github.com/ava-labs/avalanchego/ids" 8 "github.com/ava-labs/avalanchego/vms/avm/txs" 9 "github.com/ava-labs/avalanchego/vms/components/avax" 10 "github.com/ava-labs/avalanchego/vms/components/verify" 11 "github.com/ava-labs/avalanchego/vms/secp256k1fx" 12 "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" 13 ) 14 15 var _ Builder = (*builderWithOptions)(nil) 16 17 type builderWithOptions struct { 18 builder Builder 19 options []common.Option 20 } 21 22 // NewWithOptions returns a new transaction builder that will use the given 23 // options by default. 24 // 25 // - [builder] is the builder that will be called to perform the underlying 26 // operations. 27 // - [options] will be provided to the builder in addition to the options 28 // provided in the method calls. 29 func NewWithOptions(builder Builder, options ...common.Option) Builder { 30 return &builderWithOptions{ 31 builder: builder, 32 options: options, 33 } 34 } 35 36 func (b *builderWithOptions) Context() *Context { 37 return b.builder.Context() 38 } 39 40 func (b *builderWithOptions) GetFTBalance( 41 options ...common.Option, 42 ) (map[ids.ID]uint64, error) { 43 return b.builder.GetFTBalance( 44 common.UnionOptions(b.options, options)..., 45 ) 46 } 47 48 func (b *builderWithOptions) GetImportableBalance( 49 chainID ids.ID, 50 options ...common.Option, 51 ) (map[ids.ID]uint64, error) { 52 return b.builder.GetImportableBalance( 53 chainID, 54 common.UnionOptions(b.options, options)..., 55 ) 56 } 57 58 func (b *builderWithOptions) NewBaseTx( 59 outputs []*avax.TransferableOutput, 60 options ...common.Option, 61 ) (*txs.BaseTx, error) { 62 return b.builder.NewBaseTx( 63 outputs, 64 common.UnionOptions(b.options, options)..., 65 ) 66 } 67 68 func (b *builderWithOptions) NewCreateAssetTx( 69 name string, 70 symbol string, 71 denomination byte, 72 initialState map[uint32][]verify.State, 73 options ...common.Option, 74 ) (*txs.CreateAssetTx, error) { 75 return b.builder.NewCreateAssetTx( 76 name, 77 symbol, 78 denomination, 79 initialState, 80 common.UnionOptions(b.options, options)..., 81 ) 82 } 83 84 func (b *builderWithOptions) NewOperationTx( 85 operations []*txs.Operation, 86 options ...common.Option, 87 ) (*txs.OperationTx, error) { 88 return b.builder.NewOperationTx( 89 operations, 90 common.UnionOptions(b.options, options)..., 91 ) 92 } 93 94 func (b *builderWithOptions) NewOperationTxMintFT( 95 outputs map[ids.ID]*secp256k1fx.TransferOutput, 96 options ...common.Option, 97 ) (*txs.OperationTx, error) { 98 return b.builder.NewOperationTxMintFT( 99 outputs, 100 common.UnionOptions(b.options, options)..., 101 ) 102 } 103 104 func (b *builderWithOptions) NewOperationTxMintNFT( 105 assetID ids.ID, 106 payload []byte, 107 owners []*secp256k1fx.OutputOwners, 108 options ...common.Option, 109 ) (*txs.OperationTx, error) { 110 return b.builder.NewOperationTxMintNFT( 111 assetID, 112 payload, 113 owners, 114 common.UnionOptions(b.options, options)..., 115 ) 116 } 117 118 func (b *builderWithOptions) NewOperationTxMintProperty( 119 assetID ids.ID, 120 owner *secp256k1fx.OutputOwners, 121 options ...common.Option, 122 ) (*txs.OperationTx, error) { 123 return b.builder.NewOperationTxMintProperty( 124 assetID, 125 owner, 126 common.UnionOptions(b.options, options)..., 127 ) 128 } 129 130 func (b *builderWithOptions) NewOperationTxBurnProperty( 131 assetID ids.ID, 132 options ...common.Option, 133 ) (*txs.OperationTx, error) { 134 return b.builder.NewOperationTxBurnProperty( 135 assetID, 136 common.UnionOptions(b.options, options)..., 137 ) 138 } 139 140 func (b *builderWithOptions) NewImportTx( 141 chainID ids.ID, 142 to *secp256k1fx.OutputOwners, 143 options ...common.Option, 144 ) (*txs.ImportTx, error) { 145 return b.builder.NewImportTx( 146 chainID, 147 to, 148 common.UnionOptions(b.options, options)..., 149 ) 150 } 151 152 func (b *builderWithOptions) NewExportTx( 153 chainID ids.ID, 154 outputs []*avax.TransferableOutput, 155 options ...common.Option, 156 ) (*txs.ExportTx, error) { 157 return b.builder.NewExportTx( 158 chainID, 159 outputs, 160 common.UnionOptions(b.options, options)..., 161 ) 162 }