-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from BitcoinSchema/from-bpu
From bpu
- Loading branch information
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package sigma | ||
|
||
import ( | ||
"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 = *tape.Cell[startIndex+3].B | ||
} | ||
if tape.Cell[startIndex+4].S != nil { | ||
vin, err := strconv.Atoi(*tape.Cell[startIndex+4].S) | ||
if err != nil { | ||
return | ||
} | ||
s.Vin = int(vin) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters