-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbob.go
57 lines (50 loc) · 1.14 KB
/
bob.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
56
57
package sigma
import (
"encoding/hex"
"strconv"
"github.com/bitcoinschema/go-bpu"
)
func NewSigFromTape(tape bpu.Tape, vout int) (s *Sig) {
s = new(Sig)
s.FromTape(tape, vout)
return
}
// FromTape takes a BOB Tape and returns an Aip data structure.
// Using the FromTape() alone will prevent validation (data is needed via SetData to enable)
func (s *Sig) FromTape(tape bpu.Tape, vout int) {
// Not a valid tape?
if len(tape.Cell) < 4 {
return
}
// Loop to find start of AIP
var startIndex int
found := false
for i, cell := range tape.Cell {
if *cell.S == Prefix {
startIndex = i
found = true
break
}
}
if !found || len(tape.Cell) < 5 {
return
}
s.TargetVout = vout
// Set the SIGMA fields
if tape.Cell[startIndex+1].S != nil {
s.Algorithm = Algorithm(*tape.Cell[startIndex+1].S)
}
if tape.Cell[startIndex+2].S != nil {
s.Address = *tape.Cell[startIndex+2].S
}
if tape.Cell[startIndex+3].B != nil {
s.Signature, _ = hex.DecodeString(*tape.Cell[startIndex+3].H)
}
if tape.Cell[startIndex+4].S != nil {
vin, err := strconv.Atoi(*tape.Cell[startIndex+4].S)
if err != nil {
return
}
s.Vin = int(vin)
}
}