本文整理汇总了Golang中github.com/spearson78/guardian/script/scanner.Scanner.Init方法的典型用法代码示例。如果您正苦于以下问题:Golang Scanner.Init方法的具体用法?Golang Scanner.Init怎么用?Golang Scanner.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spearson78/guardian/script/scanner.Scanner
的用法示例。
在下文中一共展示了Scanner.Init方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Subscriptify
func Subscriptify(script []byte, sig []byte) ([]byte, error) {
s := new(scanner.Scanner)
s.Init(script, nil)
subscript := make([]byte, 0, len(script))
loop:
for {
tok := s.Scan()
switch tok {
case token.DATA:
//Suppress the signature
if !bytes.Equal(s.Data(), sig) {
subscript = append(subscript, s.ByteCode())
subscript = append(subscript, s.Data()...)
}
case token.CODESEPARATOR:
//Remove code separators
case token.ENDOFSCRIPT:
break loop
case token.INVALID:
return nil, errors.New("Invalid Token")
default:
//All other tokens are passed straight through
subscript = append(subscript, s.ByteCode())
}
}
if s.ErrorCount() != 0 {
return nil, errors.New("Scanner Errors Occured")
}
return subscript, nil
}
示例2: BenchmarkNops
func BenchmarkNops(b *testing.B) {
script, _ := hex.DecodeString("61616161616161616161")
s := new(scanner.Scanner)
for i := 0; i < b.N; i++ {
s.Init(script, nil)
Parse(s)
}
}
示例3: BenchmarkStandardTransactionToBitcoinAddress
func BenchmarkStandardTransactionToBitcoinAddress(b *testing.B) {
script, _ := hex.DecodeString("76A91489ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA88AC")
s := new(scanner.Scanner)
for i := 0; i < b.N; i++ {
s.Init(script, nil)
Parse(s)
}
}
示例4: TestStandardTransactionToBitcoinAddressFromScanner
func TestStandardTransactionToBitcoinAddressFromScanner(t *testing.T) {
script, _ := hex.DecodeString("76A91489ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA88AC")
s := new(scanner.Scanner)
s.Init(script, nil)
compiled, _ := Compile(s)
if !bytes.Equal(compiled, script) {
t.Errorf("Failed")
}
}
示例5: TestStandardTransactionToBitcoinAddressScanner
func TestStandardTransactionToBitcoinAddressScanner(t *testing.T) {
script, _ := hex.DecodeString("76A91489ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA88AC")
checkData, _ := hex.DecodeString("89ABCDEFABBAABBAABBAABBAABBAABBAABBAABBA")
s := new(scanner.Scanner)
errorReported := false
s.Init(script, func(pos int, msg string) {
errorReported = true
})
tree, err := Parse(s)
if err != nil {
t.Errorf("Failed %v", err)
}
root := new(SimpleBlock)
root.NodeList = []Node{
&Operation{
ParentBlock: root,
OpCode: opcode.DUP,
},
&Operation{
ParentBlock: root,
OpCode: opcode.HASH160,
},
&Data{
ParentBlock: root,
Value: checkData,
},
&Operation{
ParentBlock: root,
OpCode: opcode.EQUALVERIFY,
},
&Operation{
ParentBlock: root,
OpCode: opcode.CHECKSIG,
},
}
if !root.Equals(tree) {
t.Errorf("AST Mismatch")
}
}
示例6: execAst
func (this *Executor) execAst(script []byte) error {
s := new(scanner.Scanner)
s.Init(script, nil)
block, err := ast.Parse(s)
if err != nil {
return err
}
err = block.ForEachNode(this)
if err != nil {
return err
}
if s.ErrorCount() != 0 {
return errors.New("TokenSource reported errors")
}
return nil
}
示例7: execScanner
func (this *Executor) execScanner(script []byte) error {
s := new(scanner.Scanner)
s.Init(script, nil)
ifDepth := 0
loop:
for {
tok := s.Scan()
switch tok {
case token.DATA:
this.Push(s.Data())
case token.OPERATION:
impl := opCodeImpls[s.Op()]
if impl == nil {
return errors.New("Unknown OpCode - " + s.Op().String())
}
err := impl(&this.Context)
if err != nil {
return err
}
case token.ENDOFSCRIPT:
break loop
case token.NUMBER:
this.PushNumber(s.Number())
case token.CODESEPARATOR:
this.codeSeparatorPos = s.Pos()
case token.IF:
ifDepth++
top := this.PopBool()
if !top {
seekElse(s)
}
case token.NOTIF:
ifDepth++
top := this.PopBool()
if top {
seekElse(s)
}
case token.ELSE:
if ifDepth == 0 {
return errors.New("Unexpected EndIf")
}
ifDepth--
seekEndIf(s)
case token.ENDIF:
if ifDepth == 0 {
return errors.New("Unexpected Else")
}
ifDepth--
case token.INVALID:
return errors.New("Invalid Token")
}
}
if ifDepth != 0 {
return errors.New("Unclosed If")
}
if s.ErrorCount() != 0 {
return errors.New("TokenSource reported errors")
}
return nil
}