github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/txs/payload/perms_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  	"github.com/hyperledger/burrow/permission"
     9  )
    10  
    11  func NewPermsTx(st acmstate.AccountGetter, from *crypto.PublicKey, args permission.PermArgs) (*PermsTx, error) {
    12  	addr := from.GetAddress()
    13  	acc, err := st.GetAccount(addr)
    14  	if err != nil {
    15  		return nil, err
    16  	}
    17  	if acc == nil {
    18  		return nil, fmt.Errorf("NewPermsTx: could not find account with address %v", addr)
    19  	}
    20  
    21  	sequence := acc.Sequence + 1
    22  	return NewPermsTxWithSequence(from, args, sequence), nil
    23  }
    24  
    25  func NewPermsTxWithSequence(from *crypto.PublicKey, args permission.PermArgs, sequence uint64) *PermsTx {
    26  	input := &TxInput{
    27  		Address:  from.GetAddress(),
    28  		Amount:   1, // NOTE: amounts can't be 0 ...
    29  		Sequence: sequence,
    30  	}
    31  
    32  	return &PermsTx{
    33  		Input:    input,
    34  		PermArgs: args,
    35  	}
    36  }
    37  
    38  func (tx *PermsTx) Type() Type {
    39  	return TypePermissions
    40  }
    41  
    42  func (tx *PermsTx) GetInputs() []*TxInput {
    43  	return []*TxInput{tx.Input}
    44  }
    45  
    46  func (tx *PermsTx) String() string {
    47  	return fmt.Sprintf("PermsTx{%v -> %v}", tx.Input, tx.PermArgs)
    48  }
    49  
    50  func (tx *PermsTx) Any() *Any {
    51  	return &Any{
    52  		PermsTx: tx,
    53  	}
    54  }