github.com/ava-labs/avalanchego@v1.11.11/wallet/chain/c/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 c 5 6 import ( 7 "math/big" 8 9 "github.com/ava-labs/coreth/plugin/evm" 10 11 "github.com/ava-labs/avalanchego/ids" 12 "github.com/ava-labs/avalanchego/vms/secp256k1fx" 13 "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" 14 15 ethcommon "github.com/ethereum/go-ethereum/common" 16 ) 17 18 var _ Builder = (*builderWithOptions)(nil) 19 20 type builderWithOptions struct { 21 Builder 22 options []common.Option 23 } 24 25 // NewBuilderWithOptions returns a new transaction builder that will use the 26 // given options by default. 27 // 28 // - [builder] is the builder that will be called to perform the underlying 29 // operations. 30 // - [options] will be provided to the builder in addition to the options 31 // provided in the method calls. 32 func NewBuilderWithOptions(builder Builder, options ...common.Option) Builder { 33 return &builderWithOptions{ 34 Builder: builder, 35 options: options, 36 } 37 } 38 39 func (b *builderWithOptions) GetBalance( 40 options ...common.Option, 41 ) (*big.Int, error) { 42 return b.Builder.GetBalance( 43 common.UnionOptions(b.options, options)..., 44 ) 45 } 46 47 func (b *builderWithOptions) GetImportableBalance( 48 chainID ids.ID, 49 options ...common.Option, 50 ) (uint64, error) { 51 return b.Builder.GetImportableBalance( 52 chainID, 53 common.UnionOptions(b.options, options)..., 54 ) 55 } 56 57 func (b *builderWithOptions) NewImportTx( 58 chainID ids.ID, 59 to ethcommon.Address, 60 baseFee *big.Int, 61 options ...common.Option, 62 ) (*evm.UnsignedImportTx, error) { 63 return b.Builder.NewImportTx( 64 chainID, 65 to, 66 baseFee, 67 common.UnionOptions(b.options, options)..., 68 ) 69 } 70 71 func (b *builderWithOptions) NewExportTx( 72 chainID ids.ID, 73 outputs []*secp256k1fx.TransferOutput, 74 baseFee *big.Int, 75 options ...common.Option, 76 ) (*evm.UnsignedExportTx, error) { 77 return b.Builder.NewExportTx( 78 chainID, 79 outputs, 80 baseFee, 81 common.UnionOptions(b.options, options)..., 82 ) 83 }