github.com/ava-labs/avalanchego@v1.11.11/wallet/chain/p/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  	"time"
     8  
     9  	"github.com/ava-labs/avalanchego/ids"
    10  	"github.com/ava-labs/avalanchego/vms/components/avax"
    11  	"github.com/ava-labs/avalanchego/vms/platformvm/signer"
    12  	"github.com/ava-labs/avalanchego/vms/platformvm/txs"
    13  	"github.com/ava-labs/avalanchego/vms/secp256k1fx"
    14  	"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
    15  )
    16  
    17  var _ Builder = (*builderWithOptions)(nil)
    18  
    19  type builderWithOptions struct {
    20  	builder Builder
    21  	options []common.Option
    22  }
    23  
    24  // NewWithOptions returns a new builder that will use the given options by
    25  // default.
    26  //
    27  //   - [builder] is the builder that will be called to perform the underlying
    28  //     operations.
    29  //   - [options] will be provided to the builder in addition to the options
    30  //     provided in the method calls.
    31  func NewWithOptions(builder Builder, options ...common.Option) Builder {
    32  	return &builderWithOptions{
    33  		builder: builder,
    34  		options: options,
    35  	}
    36  }
    37  
    38  func (b *builderWithOptions) Context() *Context {
    39  	return b.builder.Context()
    40  }
    41  
    42  func (b *builderWithOptions) GetBalance(
    43  	options ...common.Option,
    44  ) (map[ids.ID]uint64, error) {
    45  	return b.builder.GetBalance(
    46  		common.UnionOptions(b.options, options)...,
    47  	)
    48  }
    49  
    50  func (b *builderWithOptions) GetImportableBalance(
    51  	chainID ids.ID,
    52  	options ...common.Option,
    53  ) (map[ids.ID]uint64, error) {
    54  	return b.builder.GetImportableBalance(
    55  		chainID,
    56  		common.UnionOptions(b.options, options)...,
    57  	)
    58  }
    59  
    60  func (b *builderWithOptions) NewBaseTx(
    61  	outputs []*avax.TransferableOutput,
    62  	options ...common.Option,
    63  ) (*txs.BaseTx, error) {
    64  	return b.builder.NewBaseTx(
    65  		outputs,
    66  		common.UnionOptions(b.options, options)...,
    67  	)
    68  }
    69  
    70  func (b *builderWithOptions) NewAddValidatorTx(
    71  	vdr *txs.Validator,
    72  	rewardsOwner *secp256k1fx.OutputOwners,
    73  	shares uint32,
    74  	options ...common.Option,
    75  ) (*txs.AddValidatorTx, error) {
    76  	return b.builder.NewAddValidatorTx(
    77  		vdr,
    78  		rewardsOwner,
    79  		shares,
    80  		common.UnionOptions(b.options, options)...,
    81  	)
    82  }
    83  
    84  func (b *builderWithOptions) NewAddSubnetValidatorTx(
    85  	vdr *txs.SubnetValidator,
    86  	options ...common.Option,
    87  ) (*txs.AddSubnetValidatorTx, error) {
    88  	return b.builder.NewAddSubnetValidatorTx(
    89  		vdr,
    90  		common.UnionOptions(b.options, options)...,
    91  	)
    92  }
    93  
    94  func (b *builderWithOptions) NewRemoveSubnetValidatorTx(
    95  	nodeID ids.NodeID,
    96  	subnetID ids.ID,
    97  	options ...common.Option,
    98  ) (*txs.RemoveSubnetValidatorTx, error) {
    99  	return b.builder.NewRemoveSubnetValidatorTx(
   100  		nodeID,
   101  		subnetID,
   102  		common.UnionOptions(b.options, options)...,
   103  	)
   104  }
   105  
   106  func (b *builderWithOptions) NewAddDelegatorTx(
   107  	vdr *txs.Validator,
   108  	rewardsOwner *secp256k1fx.OutputOwners,
   109  	options ...common.Option,
   110  ) (*txs.AddDelegatorTx, error) {
   111  	return b.builder.NewAddDelegatorTx(
   112  		vdr,
   113  		rewardsOwner,
   114  		common.UnionOptions(b.options, options)...,
   115  	)
   116  }
   117  
   118  func (b *builderWithOptions) NewCreateChainTx(
   119  	subnetID ids.ID,
   120  	genesis []byte,
   121  	vmID ids.ID,
   122  	fxIDs []ids.ID,
   123  	chainName string,
   124  	options ...common.Option,
   125  ) (*txs.CreateChainTx, error) {
   126  	return b.builder.NewCreateChainTx(
   127  		subnetID,
   128  		genesis,
   129  		vmID,
   130  		fxIDs,
   131  		chainName,
   132  		common.UnionOptions(b.options, options)...,
   133  	)
   134  }
   135  
   136  func (b *builderWithOptions) NewCreateSubnetTx(
   137  	owner *secp256k1fx.OutputOwners,
   138  	options ...common.Option,
   139  ) (*txs.CreateSubnetTx, error) {
   140  	return b.builder.NewCreateSubnetTx(
   141  		owner,
   142  		common.UnionOptions(b.options, options)...,
   143  	)
   144  }
   145  
   146  func (b *builderWithOptions) NewTransferSubnetOwnershipTx(
   147  	subnetID ids.ID,
   148  	owner *secp256k1fx.OutputOwners,
   149  	options ...common.Option,
   150  ) (*txs.TransferSubnetOwnershipTx, error) {
   151  	return b.builder.NewTransferSubnetOwnershipTx(
   152  		subnetID,
   153  		owner,
   154  		common.UnionOptions(b.options, options)...,
   155  	)
   156  }
   157  
   158  func (b *builderWithOptions) NewImportTx(
   159  	sourceChainID ids.ID,
   160  	to *secp256k1fx.OutputOwners,
   161  	options ...common.Option,
   162  ) (*txs.ImportTx, error) {
   163  	return b.builder.NewImportTx(
   164  		sourceChainID,
   165  		to,
   166  		common.UnionOptions(b.options, options)...,
   167  	)
   168  }
   169  
   170  func (b *builderWithOptions) NewExportTx(
   171  	chainID ids.ID,
   172  	outputs []*avax.TransferableOutput,
   173  	options ...common.Option,
   174  ) (*txs.ExportTx, error) {
   175  	return b.builder.NewExportTx(
   176  		chainID,
   177  		outputs,
   178  		common.UnionOptions(b.options, options)...,
   179  	)
   180  }
   181  
   182  func (b *builderWithOptions) NewTransformSubnetTx(
   183  	subnetID ids.ID,
   184  	assetID ids.ID,
   185  	initialSupply uint64,
   186  	maxSupply uint64,
   187  	minConsumptionRate uint64,
   188  	maxConsumptionRate uint64,
   189  	minValidatorStake uint64,
   190  	maxValidatorStake uint64,
   191  	minStakeDuration time.Duration,
   192  	maxStakeDuration time.Duration,
   193  	minDelegationFee uint32,
   194  	minDelegatorStake uint64,
   195  	maxValidatorWeightFactor byte,
   196  	uptimeRequirement uint32,
   197  	options ...common.Option,
   198  ) (*txs.TransformSubnetTx, error) {
   199  	return b.builder.NewTransformSubnetTx(
   200  		subnetID,
   201  		assetID,
   202  		initialSupply,
   203  		maxSupply,
   204  		minConsumptionRate,
   205  		maxConsumptionRate,
   206  		minValidatorStake,
   207  		maxValidatorStake,
   208  		minStakeDuration,
   209  		maxStakeDuration,
   210  		minDelegationFee,
   211  		minDelegatorStake,
   212  		maxValidatorWeightFactor,
   213  		uptimeRequirement,
   214  		common.UnionOptions(b.options, options)...,
   215  	)
   216  }
   217  
   218  func (b *builderWithOptions) NewAddPermissionlessValidatorTx(
   219  	vdr *txs.SubnetValidator,
   220  	signer signer.Signer,
   221  	assetID ids.ID,
   222  	validationRewardsOwner *secp256k1fx.OutputOwners,
   223  	delegationRewardsOwner *secp256k1fx.OutputOwners,
   224  	shares uint32,
   225  	options ...common.Option,
   226  ) (*txs.AddPermissionlessValidatorTx, error) {
   227  	return b.builder.NewAddPermissionlessValidatorTx(
   228  		vdr,
   229  		signer,
   230  		assetID,
   231  		validationRewardsOwner,
   232  		delegationRewardsOwner,
   233  		shares,
   234  		common.UnionOptions(b.options, options)...,
   235  	)
   236  }
   237  
   238  func (b *builderWithOptions) NewAddPermissionlessDelegatorTx(
   239  	vdr *txs.SubnetValidator,
   240  	assetID ids.ID,
   241  	rewardsOwner *secp256k1fx.OutputOwners,
   242  	options ...common.Option,
   243  ) (*txs.AddPermissionlessDelegatorTx, error) {
   244  	return b.builder.NewAddPermissionlessDelegatorTx(
   245  		vdr,
   246  		assetID,
   247  		rewardsOwner,
   248  		common.UnionOptions(b.options, options)...,
   249  	)
   250  }