forked from BitcoinSchema/go-bmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmap.go
More file actions
63 lines (58 loc) · 1.66 KB
/
bmap.go
File metadata and controls
63 lines (58 loc) · 1.66 KB
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
56
57
58
59
60
61
62
63
package bmap
import (
"github.com/bitcoinschema/go-aip"
"github.com/bitcoinschema/go-b"
"github.com/bitcoinschema/go-bap"
"github.com/bitcoinschema/go-bob"
magic "github.com/bitcoinschema/go-map"
)
// Tx is a Bmap formatted tx
type Tx struct {
AIP *aip.Aip `json:"AIP,omitempty" bson:"AIP,omitempty"`
B *b.B `json:"B,omitempty" bson:"B,omitempty"`
BAP *bap.Bap `json:"BAP,omitempty" bson:"BAP,omitempty"`
Blk bob.Blk `json:"blk,omitempty" bson:"blk,omitempty"`
In []bob.Input `json:"in,omitempty" bson:"in,omitempty"`
MAP magic.MAP `json:"MAP,omitempty" bson:"MAP,omitempty"`
Out []bob.Output `json:"out,omitempty" bson:"out,omitempty"`
Tx bob.TxInfo `json:"tx,omitempty" bson:"tx,omitempty"`
}
// NewFromBob returns a new BmapTx from a BobTx
func NewFromBob(bobTx *bob.Tx) (bmapTx *Tx, err error) {
bmapTx = new(Tx)
err = bmapTx.FromBob(bobTx)
return
}
// FromBob returns a BmapTx from a BobTx
func (t *Tx) FromBob(bobTx *bob.Tx) (err error) {
for _, out := range bobTx.Out {
for index, tape := range out.Tape {
if len(tape.Cell) > 0 {
prefixData := tape.Cell[0].S
switch prefixData {
case aip.Prefix:
t.AIP = aip.NewFromTape(tape)
t.AIP.SetDataFromTapes(out.Tape)
case bap.Prefix:
if t.BAP, err = bap.NewFromTape(&out.Tape[index]); err != nil {
return
}
case magic.Prefix:
if t.MAP, err = magic.NewFromTape(&out.Tape[index]); err != nil {
return
}
case b.Prefix:
if t.B, err = b.NewFromTape(out.Tape[index]); err != nil {
return
}
}
}
}
// Set inherited fields
t.Blk = bobTx.Blk
t.In = bobTx.In
t.Out = bobTx.Out
t.Tx = bobTx.Tx
}
return
}