github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/txs/payload/name_tx.go (about)

     1  package payload
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hyperledger/burrow/acm/acmstate"
     7  	"github.com/hyperledger/burrow/crypto"
     8  )
     9  
    10  func NewNameTx(st acmstate.AccountGetter, from *crypto.PublicKey, name, data string, amt, fee uint64) (*NameTx, error) {
    11  	addr := from.GetAddress()
    12  	acc, err := st.GetAccount(addr)
    13  	if err != nil {
    14  		return nil, err
    15  	}
    16  	if acc == nil {
    17  		return nil, fmt.Errorf("NewNameTx: could not find account with address %v", addr)
    18  	}
    19  
    20  	sequence := acc.Sequence + 1
    21  	return NewNameTxWithSequence(from, name, data, amt, fee, sequence), nil
    22  }
    23  
    24  func NewNameTxWithSequence(from *crypto.PublicKey, name, data string, amt, fee, sequence uint64) *NameTx {
    25  	input := &TxInput{
    26  		Address:  from.GetAddress(),
    27  		Amount:   amt,
    28  		Sequence: sequence,
    29  	}
    30  
    31  	return &NameTx{
    32  		Input: input,
    33  		Name:  name,
    34  		Data:  data,
    35  		Fee:   fee,
    36  	}
    37  }
    38  
    39  func (tx *NameTx) Type() Type {
    40  	return TypeName
    41  }
    42  
    43  func (tx *NameTx) GetInputs() []*TxInput {
    44  	return []*TxInput{tx.Input}
    45  }
    46  
    47  func (tx *NameTx) String() string {
    48  	return fmt.Sprintf("NameTx{%v -> %s: %s}", tx.Input, tx.Name, tx.Data)
    49  }
    50  
    51  func (tx *NameTx) Any() *Any {
    52  	return &Any{
    53  		NameTx: tx,
    54  	}
    55  }