forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
name_tx.go
55 lines (45 loc) · 1.09 KB
/
name_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
package payload
import (
"fmt"
"github.com/hyperledger/burrow/acm/state"
"github.com/hyperledger/burrow/crypto"
)
func NewNameTx(st state.AccountGetter, from crypto.PublicKey, name, data string, amt, fee uint64) (*NameTx, error) {
addr := from.Address()
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 NewNameTxWithSequence(from, name, data, amt, fee, sequence), nil
}
func NewNameTxWithSequence(from crypto.PublicKey, name, data string, amt, fee, sequence uint64) *NameTx {
input := &TxInput{
Address: from.Address(),
Amount: amt,
Sequence: sequence,
}
return &NameTx{
Input: input,
Name: name,
Data: data,
Fee: fee,
}
}
func (tx *NameTx) Type() Type {
return TypeName
}
func (tx *NameTx) GetInputs() []*TxInput {
return []*TxInput{tx.Input}
}
func (tx *NameTx) String() string {
return fmt.Sprintf("NameTx{%v -> %s: %s}", tx.Input, tx.Name, tx.Data)
}
func (tx *NameTx) Any() *Any {
return &Any{
NameTx: tx,
}
}