当前位置: 首页>>代码示例>>Golang>>正文


Golang scanner.Scanner类代码示例

本文整理汇总了Golang中github.com/spearson78/guardian/script/scanner.Scanner的典型用法代码示例。如果您正苦于以下问题:Golang Scanner类的具体用法?Golang Scanner怎么用?Golang Scanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Scanner类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: seekElse

func seekElse(s *scanner.Scanner) error {
	ifDepth := 0
loop:
	for {

		tok := s.Scan()
		switch tok {
		case token.ENDOFSCRIPT:
			return errors.New("Unclosed IF Statements")
		case token.IF:
			ifDepth++
		case token.ENDIF:
			if ifDepth == 0 {
				break loop
			} else {
				ifDepth--
			}
		case token.ELSE:
			if ifDepth == 0 {
				break loop
			}
		}
	}

	return nil
}
开发者ID:spearson78,项目名称:guardian,代码行数:26,代码来源:executor_scanner.go

示例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)
	}
}
开发者ID:spearson78,项目名称:guardian,代码行数:10,代码来源:ast_test.go

示例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)
	}
}
开发者ID:spearson78,项目名称:guardian,代码行数:10,代码来源:ast_test.go

示例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")
	}

}
开发者ID:spearson78,项目名称:guardian,代码行数:13,代码来源:compiler_test.go

示例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")
	}

}
开发者ID:spearson78,项目名称:guardian,代码行数:47,代码来源:ast_test.go

示例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
}
开发者ID:spearson78,项目名称:guardian,代码行数:19,代码来源:executor_ast.go

示例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
}
开发者ID:spearson78,项目名称:guardian,代码行数:68,代码来源:executor_scanner.go

示例8: 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
}
开发者ID:spearson78,项目名称:guardian,代码行数:35,代码来源:crypto_subscript.go


注:本文中的github.com/spearson78/guardian/script/scanner.Scanner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。