This repository has been archived by the owner on May 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 346
/
call_tx.go
67 lines (56 loc) · 1.48 KB
/
call_tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package payload
import (
"fmt"
"github.com/hyperledger/burrow/acm/state"
"github.com/hyperledger/burrow/crypto"
)
func NewCallTx(st state.AccountGetter, from crypto.PublicKey, to *crypto.Address, data []byte,
amt, gasLimit, fee uint64) (*CallTx, error) {
addr := from.GetAddress()
acc, err := st.GetAccount(addr)
if err != nil {
return nil, err
}
if acc == nil {
return nil, fmt.Errorf("invalid address %s from pubkey %s", addr, from)
}
sequence := acc.Sequence + 1
return NewCallTxWithSequence(from, to, data, amt, gasLimit, fee, sequence), nil
}
func NewCallTxWithSequence(from crypto.PublicKey, to *crypto.Address, data []byte,
amt, gasLimit, fee, sequence uint64) *CallTx {
input := &TxInput{
Address: from.GetAddress(),
Amount: amt,
Sequence: sequence,
}
return &CallTx{
Input: input,
Address: to,
GasLimit: gasLimit,
Fee: fee,
Data: data,
}
}
func (tx *CallTx) Type() Type {
return TypeCall
}
func (tx *CallTx) GetInputs() []*TxInput {
return []*TxInput{tx.Input}
}
func (tx *CallTx) String() string {
return fmt.Sprintf("CallTx{%v -> %s: %v}", tx.Input, tx.Address, tx.Data)
}
// Returns the contract address that this CallTx would create if CallTx.Address == nil otherwise returns nil
func (tx *CallTx) CreatesContractAddress() *crypto.Address {
if tx.Address != nil {
return nil
}
address := crypto.NewContractAddress(tx.Input.Address, tx.Input.Sequence)
return &address
}
func (tx *CallTx) Any() *Any {
return &Any{
CallTx: tx,
}
}