github.com/ava-labs/avalanchego@v1.11.11/wallet/chain/p/client.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package p
     5  
     6  import (
     7  	"github.com/ava-labs/avalanchego/vms/platformvm"
     8  	"github.com/ava-labs/avalanchego/vms/platformvm/txs"
     9  	"github.com/ava-labs/avalanchego/wallet/chain/p/wallet"
    10  	"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
    11  )
    12  
    13  var _ wallet.Client = (*Client)(nil)
    14  
    15  func NewClient(
    16  	c platformvm.Client,
    17  	b wallet.Backend,
    18  ) *Client {
    19  	return &Client{
    20  		client:  c,
    21  		backend: b,
    22  	}
    23  }
    24  
    25  type Client struct {
    26  	client  platformvm.Client
    27  	backend wallet.Backend
    28  }
    29  
    30  func (c *Client) IssueTx(
    31  	tx *txs.Tx,
    32  	options ...common.Option,
    33  ) error {
    34  	ops := common.NewOptions(options)
    35  	ctx := ops.Context()
    36  	txID, err := c.client.IssueTx(ctx, tx.Bytes())
    37  	if err != nil {
    38  		return err
    39  	}
    40  
    41  	if f := ops.PostIssuanceFunc(); f != nil {
    42  		f(txID)
    43  	}
    44  
    45  	if ops.AssumeDecided() {
    46  		return c.backend.AcceptTx(ctx, tx)
    47  	}
    48  
    49  	if err := platformvm.AwaitTxAccepted(c.client, ctx, txID, ops.PollFrequency()); err != nil {
    50  		return err
    51  	}
    52  
    53  	return c.backend.AcceptTx(ctx, tx)
    54  }