forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bond_tx.go
62 lines (52 loc) · 1.27 KB
/
bond_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
package payload
import (
"fmt"
"github.com/hyperledger/burrow/acm/state"
"github.com/hyperledger/burrow/crypto"
)
func NewBondTx(pubkey crypto.PublicKey) (*BondTx, error) {
return &BondTx{
Inputs: []*TxInput{},
UnbondTo: []*TxOutput{},
}, nil
}
func (tx *BondTx) Type() Type {
return TypeBond
}
func (tx *BondTx) GetInputs() []*TxInput {
return tx.Inputs
}
func (tx *BondTx) String() string {
return fmt.Sprintf("BondTx{%v -> %v}", tx.Inputs, tx.UnbondTo)
}
func (tx *BondTx) AddInput(st state.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("Invalid address %s from pubkey %s", addr, pubkey)
}
return tx.AddInputWithSequence(pubkey, amt, acc.Sequence+uint64(1))
}
func (tx *BondTx) AddInputWithSequence(pubkey crypto.PublicKey, amt uint64, sequence uint64) error {
tx.Inputs = append(tx.Inputs, &TxInput{
Address: pubkey.GetAddress(),
Amount: amt,
Sequence: sequence,
})
return nil
}
func (tx *BondTx) AddOutput(addr crypto.Address, amt uint64) error {
tx.UnbondTo = append(tx.UnbondTo, &TxOutput{
Address: addr,
Amount: amt,
})
return nil
}
func (tx *BondTx) Any() *Any {
return &Any{
BondTx: tx,
}
}