-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
36 lines (31 loc) · 1.02 KB
/
helpers.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
package proto_016_PtMumbai
import (
tz "github.com/ecadlabs/gotez/v2"
"github.com/ecadlabs/gotez/v2/encoding"
)
type UnsignedOperation struct {
Branch *tz.BlockHash `json:"branch"`
Contents []OperationContents `json:"contents"`
}
type SignedOperation struct {
UnsignedOperation
Signature *tz.GenericSignature `json:"signature"`
}
func (op *SignedOperation) DecodeTZ(data []byte, ctx *encoding.Context) (rest []byte, err error) {
if data, err = encoding.Decode(data, &op.Branch, encoding.Ctx(ctx)); err != nil {
return nil, err
}
if len(data) < tz.GenericSignatureBytesLen {
return nil, encoding.ErrBuffer(len(data))
}
tmp := data[:len(data)-tz.GenericSignatureBytesLen]
data = data[len(data)-tz.GenericSignatureBytesLen:]
if _, err := encoding.Decode(tmp, &op.Contents, encoding.Ctx(ctx)); err != nil {
return nil, err
}
return encoding.Decode(data, &op.Signature, encoding.Ctx(ctx))
}
type RunOperationRequest struct {
Operation SignedOperation `json:"operation"`
ChainID *tz.ChainID `json:"chain_id"`
}