forked from Onyx-Protocol/Onyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.go
41 lines (33 loc) · 1.01 KB
/
actions.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
package txbuilder
import (
"context"
stdjson "encoding/json"
"time"
"chain/encoding/json"
"chain/protocol/bc"
)
func DecodeControlProgramAction(data []byte) (Action, error) {
a := new(controlProgramAction)
err := stdjson.Unmarshal(data, a)
return a, err
}
type controlProgramAction struct {
bc.AssetAmount
Program json.HexBytes `json:"control_program"`
ReferenceData json.Map `json:"reference_data"`
}
func (c *controlProgramAction) Build(ctx context.Context, maxTime time.Time) (*BuildResult, error) {
out := bc.NewTxOutput(c.AssetID, c.Amount, c.Program, c.ReferenceData)
return &BuildResult{Outputs: []*bc.TxOutput{out}}, nil
}
func DecodeSetTxRefDataAction(data []byte) (Action, error) {
a := new(setTxRefDataAction)
err := stdjson.Unmarshal(data, a)
return a, err
}
type setTxRefDataAction struct {
Data json.Map `json:"reference_data"`
}
func (a *setTxRefDataAction) Build(ctx context.Context, maxTime time.Time) (*BuildResult, error) {
return &BuildResult{ReferenceData: a.Data}, nil
}