github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/blockchain/txbuilder/types.go (about)

     1  package txbuilder
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  
     7  	"github.com/bytom/bytom/crypto/ed25519/chainkd"
     8  	chainjson "github.com/bytom/bytom/encoding/json"
     9  	"github.com/bytom/bytom/protocol/bc"
    10  	"github.com/bytom/bytom/protocol/bc/types"
    11  )
    12  
    13  // Template represents a partially- or fully-signed transaction.
    14  type Template struct {
    15  	Transaction         *types.Tx             `json:"raw_transaction"`
    16  	SigningInstructions []*SigningInstruction `json:"signing_instructions"`
    17  	Fee                 uint64                `json:"fee"`
    18  	// AllowAdditional affects whether Sign commits to the tx sighash or
    19  	// to individual details of the tx so far. When true, signatures
    20  	// commit to tx details, and new details may be added but existing
    21  	// ones cannot be changed. When false, signatures commit to the tx
    22  	// as a whole, and any change to the tx invalidates the signature.
    23  	AllowAdditional bool `json:"allow_additional_actions"`
    24  }
    25  
    26  // Hash return sign hash
    27  func (t *Template) Hash(idx uint32) bc.Hash {
    28  	return t.Transaction.SigHash(idx)
    29  }
    30  
    31  // Action is a interface
    32  type Action interface {
    33  	Build(context.Context, *TemplateBuilder) error
    34  	ActionType() string
    35  }
    36  
    37  // Receiver encapsulates information about where to send assets.
    38  type Receiver struct {
    39  	ControlProgram chainjson.HexBytes `json:"control_program,omitempty"`
    40  	Address        string             `json:"address,omitempty"`
    41  }
    42  
    43  // ContractArgument for smart contract
    44  type ContractArgument struct {
    45  	Type    string          `json:"type"`
    46  	RawData json.RawMessage `json:"raw_data"`
    47  }
    48  
    49  // RawTxSigArgument is signature-related argument for run contract
    50  type RawTxSigArgument struct {
    51  	RootXPub chainkd.XPub         `json:"xpub"`
    52  	Path     []chainjson.HexBytes `json:"derivation_path"`
    53  }
    54  
    55  // DataArgument is the other argument for run contract
    56  type DataArgument struct {
    57  	Value chainjson.HexBytes `json:"value"`
    58  }
    59  
    60  // StrArgument is the string argument for run contract
    61  type StrArgument struct {
    62  	Value string `json:"value"`
    63  }
    64  
    65  // IntegerArgument is the integer argument for run contract
    66  type IntegerArgument struct {
    67  	Value int64 `json:"value"`
    68  }
    69  
    70  // BoolArgument is the boolean argument for run contract
    71  type BoolArgument struct {
    72  	Value bool `json:"value"`
    73  }