Skip to content

Commit bd9d22a

Browse files
author
Jad Wahab
committed
Merge pull request #34 from libsv/feat/bscript-interpreter
1 parent 26dc44e commit bd9d22a

39 files changed

+11792
-38
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
# Output of the go coverage tool, specifically when used with LiteIDE
88
*.out
99

10+
# linter binary
11+
golangci-lint
12+
1013
# Notes
1114
todo.md
1215

1316
# Distribution directory for releases
1417
dist
1518

1619
# Converage
17-
coverage.txt
20+
coverage.txt
21+
22+
# vim
23+
*.swp

.golangci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ linters:
339339
- golint
340340
- unconvert
341341
- dupl
342-
- maligned
343342
- misspell
344343
- dogsled
344+
- revive
345345
- prealloc
346346
- exportloopref
347347
- exhaustive
@@ -356,6 +356,8 @@ linters:
356356
- gci
357357
- wsl
358358
- goerr113
359+
- scopelint
360+
- maligned
359361
- godot
360362
- testpackage
361363
- nestif
@@ -385,6 +387,7 @@ issues:
385387
- errcheck
386388
- dupl
387389
- gosec
390+
- govet
388391
- maligned
389392
- lll
390393

@@ -462,4 +465,4 @@ severity:
462465
rules:
463466
- linters:
464467
- dupl
465-
severity: info
468+
severity: info

.make/go.mk

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,10 @@ install-go: ## Install the application (Using Native Go)
4141
@go install $(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME)
4242

4343
lint: ## Run the golangci-lint application (install if not found)
44-
@#Travis (has sudo)
45-
@if [ "$(shell command -v golangci-lint)" = "" ] && [ $(TRAVIS) ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.33.0 && sudo cp ./bin/golangci-lint $(go env GOPATH)/bin/; fi;
46-
@#AWS CodePipeline
47-
@if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(CODEBUILD_BUILD_ID)" != "" ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.33.0; fi;
48-
@#Github Actions
49-
@if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(GITHUB_WORKFLOW)" != "" ]; then curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.33.0; fi;
50-
@#Brew - MacOS
51-
@if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(shell command -v brew)" != "" ]; then brew install golangci-lint; fi;
44+
@echo "downloading golangci-lint..."
45+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- v1.33.0
5246
@echo "running golangci-lint..."
53-
@golangci-lint run
47+
@GOGC=20 ./bin/golangci-lint run
5448

5549
test: ## Runs vet, lint and ALL tests
5650
@$(MAKE) lint
@@ -97,4 +91,4 @@ update-linter: ## Update the golangci-lint package (macOS only)
9791

9892
vet: ## Run the Go vet application
9993
@echo "running go vet..."
100-
@go vet -v ./...
94+
@go vet -v ./...

bscript/interpreter/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
interpreter
2+
========
3+
4+
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
5+
[![GoDoc](https://pkg.go.dev/badge/github.com/libsv/go-bt/bscript/interpreter?utm_source=godoc)](http://godoc.org/github.com/libsv/got-bt/bscript/interpreter)
6+
7+
Package interpreter implements the an interpreter for the bitcoin transaction language. There is
8+
a comprehensive test suite.
9+
10+
This package has intentionally been designed so it can be used as a standalone
11+
package for any projects needing to use or validate bitcoin transaction scripts.
12+
13+
## Bitcoin Scripts
14+
15+
Bitcoin provides a stack-based, FORTH-like language for the scripts in
16+
the bitcoin transactions. This language is not turing complete
17+
although it is still fairly powerful. A description of the language
18+
can be found at https://wiki.bitcoinsv.io/index.php/Script
19+
20+
## Installation and Updating
21+
22+
```bash
23+
$ go get -u github.com/libsv/go-bt/bscript/interpreter
24+
```
25+
26+
## Examples
27+
28+
* [Standard Pay-to-pubkey-hash Script](http://github.com/libsv/go-bt/bscript/interpreter#example-PayToAddrScript)
29+
Demonstrates creating a script which pays to a bitcoin address. It also
30+
prints the created script hex and uses the DisasmString function to display
31+
the disassembled script.
32+
33+
## License
34+
35+
Package interpreter is licensed under the [copyfree](http://copyfree.org) ISC
36+
License.

bscript/interpreter/config.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package interpreter
2+
3+
import "math"
4+
5+
type config interface {
6+
MaxOps() int
7+
MaxStackSize() int
8+
MaxScriptSize() int
9+
MaxScriptElementSize() int
10+
MaxPubKeysPerMultiSig() int
11+
}
12+
13+
// Limits applied to transactions before genesis
14+
const (
15+
MaxOpsBeforeGenesis = 500
16+
MaxStackSizeBeforeGenesis = 1000
17+
MaxScriptSizeBeforeGenesis = 10000
18+
MaxScriptElementSizeBeforeGenesis = 520
19+
MaxPubKeysPerMultiSigBeforeGenesis = 20
20+
)
21+
22+
type beforeGenesisConfig struct{}
23+
type afterGenesisConfig struct{}
24+
25+
func (a *afterGenesisConfig) MaxStackSize() int {
26+
return math.MaxInt32
27+
}
28+
29+
func (b *beforeGenesisConfig) MaxStackSize() int {
30+
return MaxStackSizeBeforeGenesis
31+
}
32+
33+
func (a *afterGenesisConfig) MaxScriptSize() int {
34+
return math.MaxInt32
35+
}
36+
37+
func (b *beforeGenesisConfig) MaxScriptSize() int {
38+
return MaxScriptSizeBeforeGenesis
39+
}
40+
41+
func (a *afterGenesisConfig) MaxScriptElementSize() int {
42+
return math.MaxInt32
43+
}
44+
45+
func (b *beforeGenesisConfig) MaxScriptElementSize() int {
46+
return MaxScriptElementSizeBeforeGenesis
47+
}
48+
49+
func (a *afterGenesisConfig) MaxOps() int {
50+
return math.MaxInt32
51+
}
52+
53+
func (b *beforeGenesisConfig) MaxOps() int {
54+
return MaxOpsBeforeGenesis
55+
}
56+
57+
func (a *afterGenesisConfig) MaxPubKeysPerMultiSig() int {
58+
return math.MaxInt32
59+
}
60+
61+
func (b *beforeGenesisConfig) MaxPubKeysPerMultiSig() int {
62+
return MaxPubKeysPerMultiSigBeforeGenesis
63+
}

bscript/interpreter/consensus.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2015-2016 The btcsuite developers
2+
// Use of this source code is governed by an ISC
3+
// license that can be found in the LICENSE file.
4+
5+
package interpreter
6+
7+
const (
8+
// LockTimeThreshold is the number below which a lock time is
9+
// interpreted to be a block number. Since an average of one block
10+
// is generated per 10 minutes, this allows blocks for about 9,512
11+
// years.
12+
LockTimeThreshold = 5e8 // Tue Nov 5 00:53:20 1985 UTC
13+
)

bscript/interpreter/data/LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The json files in this directory come from the bitcoind project
2+
(https://github.com/bitcoin/bitcoin) and is released under the following
3+
license:
4+
5+
Copyright (c) 2012-2014 The Bitcoin Core developers
6+
Distributed under the MIT/X11 software license, see the accompanying
7+
file COPYING or http://www.opensource.org/licenses/mit-license.php.
8+

0 commit comments

Comments
 (0)