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