forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_tx.go
63 lines (53 loc) · 1.24 KB
/
send_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
package payload
import (
"fmt"
"github.com/hyperledger/burrow/acm/acmstate"
"github.com/hyperledger/burrow/crypto"
)
func NewSendTx() *SendTx {
return &SendTx{
Inputs: []*TxInput{},
Outputs: []*TxOutput{},
}
}
func (tx *SendTx) GetInputs() []*TxInput {
return tx.Inputs
}
func (tx *SendTx) Type() Type {
return TypeSend
}
func (tx *SendTx) String() string {
return fmt.Sprintf("SendTx{%v -> %v}", tx.Inputs, tx.Outputs)
}
func (tx *SendTx) AddInput(st acmstate.AccountGetter, pubkey crypto.PublicKey, amt uint64) error {
addr := pubkey.GetAddress()
acc, err := st.GetAccount(addr)
if err != nil {
return err
}
if acc == nil {
return fmt.Errorf("AddInput: could not find account with address %v", addr)
}
return tx.AddInputWithSequence(pubkey, amt, acc.Sequence+1)
}
func (tx *SendTx) AddInputWithSequence(pubkey crypto.PublicKey, amt uint64, sequence uint64) error {
addr := pubkey.GetAddress()
tx.Inputs = append(tx.Inputs, &TxInput{
Address: addr,
Amount: amt,
Sequence: sequence,
})
return nil
}
func (tx *SendTx) AddOutput(addr crypto.Address, amt uint64) error {
tx.Outputs = append(tx.Outputs, &TxOutput{
Address: addr,
Amount: amt,
})
return nil
}
func (tx *SendTx) Any() *Any {
return &Any{
SendTx: tx,
}
}