-
Notifications
You must be signed in to change notification settings - Fork 28
/
transaction.go
46 lines (36 loc) · 1.13 KB
/
transaction.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
package types
import (
// RPC
"github.com/go-steem/rpc/encoding/transaction"
// Vendor
"github.com/pkg/errors"
)
// Transaction represents a blockchain transaction.
type Transaction struct {
RefBlockNum UInt16 `json:"ref_block_num"`
RefBlockPrefix UInt32 `json:"ref_block_prefix"`
Expiration *Time `json:"expiration"`
Operations Operations `json:"operations"`
Signatures []string `json:"signatures"`
}
// MarshalTransaction implements transaction.Marshaller interface.
func (tx *Transaction) MarshalTransaction(encoder *transaction.Encoder) error {
if len(tx.Operations) == 0 {
return errors.New("no operation specified")
}
enc := transaction.NewRollingEncoder(encoder)
enc.Encode(tx.RefBlockNum)
enc.Encode(tx.RefBlockPrefix)
enc.Encode(tx.Expiration)
enc.EncodeUVarint(uint64(len(tx.Operations)))
for _, op := range tx.Operations {
enc.Encode(op)
}
// Extensions are not supported yet.
enc.EncodeUVarint(0)
return enc.Err()
}
// PushOperation can be used to add an operation into the transaction.
func (tx *Transaction) PushOperation(op Operation) {
tx.Operations = append(tx.Operations, op)
}