forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perms_tx.go
54 lines (44 loc) · 1.13 KB
/
perms_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
package payload
import (
"fmt"
"github.com/hyperledger/burrow/acm/state"
"github.com/hyperledger/burrow/crypto"
"github.com/hyperledger/burrow/permission"
)
func NewPermsTx(st state.AccountGetter, from crypto.PublicKey, args permission.PermArgs) (*PermsTx, 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 NewPermsTxWithSequence(from, args, sequence), nil
}
func NewPermsTxWithSequence(from crypto.PublicKey, args permission.PermArgs, sequence uint64) *PermsTx {
input := &TxInput{
Address: from.GetAddress(),
Amount: 1, // NOTE: amounts can't be 0 ...
Sequence: sequence,
}
return &PermsTx{
Input: input,
PermArgs: args,
}
}
func (tx *PermsTx) Type() Type {
return TypePermissions
}
func (tx *PermsTx) GetInputs() []*TxInput {
return []*TxInput{tx.Input}
}
func (tx *PermsTx) String() string {
return fmt.Sprintf("PermsTx{%v -> %v}", tx.Input, tx.PermArgs)
}
func (tx *PermsTx) Any() *Any {
return &Any{
PermsTx: tx,
}
}