├── .dockerignore ├── .env ├── .github └── settings.yml ├── .gitignore ├── .pep8 ├── .pylintrc ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cargo.toml ├── Jenkinsfile ├── LICENSE ├── MAINTAINERS.md ├── README.md ├── VERSION ├── bin ├── authorize-cicd ├── generate_cli_output ├── get_version ├── run_docker_test ├── run_go_fmt ├── run_tests ├── seth-protogen └── test-entrypoint ├── ci ├── sawtooth-seth-cli ├── sawtooth-seth-cli-go ├── sawtooth-seth-rpc └── sawtooth-seth-tp ├── cli-go ├── Dockerfile ├── Dockerfile-installed-bionic ├── Dockerfile-installed-xenial ├── packaging │ └── ubuntu │ │ ├── changelog │ │ └── control └── src │ └── seth_cli │ ├── cli │ ├── account.go │ ├── account_create.go │ ├── account_import.go │ ├── account_list.go │ ├── contract.go │ ├── contract_call.go │ ├── contract_create.go │ ├── contract_list.go │ ├── data.go │ ├── init.go │ ├── main.go │ ├── permissions.go │ ├── permissions_set.go │ ├── show.go │ ├── show_account.go │ ├── show_events.go │ └── show_receipt.go │ └── client │ ├── client.go │ ├── encoder.go │ └── response.go ├── cli ├── Cargo.toml ├── Dockerfile ├── Dockerfile-installed-bionic ├── Dockerfile-installed-xenial ├── packaging │ └── ubuntu │ │ ├── changelog │ │ └── control └── src │ ├── cli │ ├── account.rs │ ├── config.rs │ ├── contract.rs │ ├── event.rs │ ├── mod.rs │ ├── permissions.rs │ └── receipt.rs │ ├── client.rs │ ├── main.rs │ └── types.rs ├── common └── src │ └── common │ ├── constants.go │ ├── evm_address.go │ └── state_address.go ├── contracts └── examples │ ├── contract_chaining │ ├── hello_world.sol │ ├── hello_world.txt │ ├── hello_world_caller.sol │ └── hello_world_caller.txt │ ├── opcodes │ ├── BlockHash.sol │ ├── BlockHash.txt │ ├── BlockNumber.sol │ ├── BlockNumber.txt │ ├── Timestamp.sol │ └── Timestamp.txt │ └── simple_intkey │ ├── simple_intkey.sol │ └── simple_intkey.txt ├── docker-compose-installed.yaml ├── docker-compose.yaml ├── docker └── compose │ └── copy-debs.yaml ├── docs ├── Dockerfile ├── Makefile ├── make.bat └── source │ ├── _templates │ └── indexcontent.html │ ├── cli_reference.rst │ ├── community.rst │ ├── community │ ├── code_of_conduct.rst │ ├── contributing.rst │ ├── issue_tracking.rst │ └── join_the_discussion.rst │ ├── conf.py │ ├── contents.rst │ ├── contracts.rst │ ├── dapps.rst │ ├── getting_started.rst │ ├── images │ ├── seth_JSON_RPC.pdf │ └── seth_JSON_RPC.svg │ ├── introduction.rst │ ├── permissions.rst │ └── seth_transaction_family_spec.rst ├── integration └── sawtooth_integration │ ├── docker │ ├── seth_blockhash_test.yaml │ ├── seth_blocknum_test.yaml │ ├── seth_chaining_test.yaml │ ├── seth_client_test.yaml │ ├── seth_intkey_test.yaml │ ├── seth_perm_test.yaml │ └── seth_timestamp_test.yaml │ └── tests │ ├── seth_blockhash_test.go │ ├── seth_blocknum_test.go │ ├── seth_chaining_test.go │ ├── seth_client_test.go │ ├── seth_intkey_test.go │ ├── seth_perm_test.go │ └── seth_timestamp_test.go ├── processor ├── Dockerfile ├── Dockerfile-installed-bionic ├── Dockerfile-installed-xenial ├── packaging │ └── ubuntu │ │ ├── changelog │ │ └── control └── src │ └── seth_tp │ ├── handler │ ├── handler.go │ ├── sawtooth_app_state.go │ ├── sawtooth_event_fireable.go │ ├── state_manager.go │ └── transaction_handlers.go │ └── main.go ├── protos ├── block_info.proto └── seth.proto ├── rpc ├── Cargo.toml ├── Dockerfile ├── Dockerfile-installed-bionic ├── Dockerfile-installed-xenial ├── build.rs ├── comp_seth_rpc.yaml ├── packaging │ └── ubuntu │ │ ├── changelog │ │ └── control ├── src │ ├── accounts.rs │ ├── calls │ │ ├── account.rs │ │ ├── block.rs │ │ ├── error.rs │ │ ├── logs.rs │ │ ├── mod.rs │ │ ├── network.rs │ │ ├── personal.rs │ │ ├── seth.rs │ │ └── transaction.rs │ ├── client.rs │ ├── filters.rs │ ├── main.rs │ ├── messages │ │ └── mod.rs │ ├── requests.rs │ ├── transactions.rs │ └── transform.rs └── tests │ ├── Dockerfile │ ├── data │ └── test.pem │ ├── mock_validator.py │ ├── rpc_client.py │ └── test_seth_rpc.py └── tests ├── addresses_test.go ├── encoder_test.go └── unit_seth.yaml /.dockerignore: -------------------------------------------------------------------------------- 1 | # Exclude IDE and Editor files 2 | /.idea/ 3 | *.sublime* 4 | 5 | 6 | # Everything else 7 | /build/ 8 | /target/ 9 | 10 | /docs/build/ 11 | /docs/source/_autogen/ 12 | /docs/source/cli/output/ 13 | 14 | /integration/**/__pycache__/ 15 | 16 | # Go binaries 17 | /*/bin/ 18 | 19 | # Auto-generated protobuf 20 | /common/src/protobuf 21 | **/src/messages/*.rs 22 | !**/src/messages/mod.rs 23 | /rpc/tests/protobuf/ 24 | 25 | # Don't lock dependencies 26 | Cargo.lock 27 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | ISOLATION_ID=latest 2 | DISTRO=bionic 3 | -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Cargill Incorporated 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | repository: 16 | # See https://developer.github.com/v3/repos/#edit for all available settings. 17 | name: sawtooth-seth 18 | homepage: https://wiki.hyperledger.org/display/sawtooth 19 | private: false 20 | has_issues: true 21 | has_projects: false 22 | has_wiki: false 23 | has_downloads: false 24 | default_branch: main 25 | allow_squash_merge: false 26 | allow_merge_commit: true 27 | allow_rebase_merge: true 28 | archived: true 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Exclude IDE and Editor files 2 | /.idea/ 3 | *.sublime* 4 | 5 | 6 | # Everything else 7 | /build/ 8 | /target/ 9 | 10 | /docs/build/ 11 | /docs/source/_autogen/ 12 | /docs/source/cli/output/ 13 | 14 | /integration/**/__pycache__/ 15 | 16 | # Go binaries 17 | /*/bin/ 18 | 19 | # Auto-generated protobuf 20 | /common/src/protobuf 21 | /rpc/tests/protobuf/ 22 | 23 | # Don't lock dependencies 24 | Cargo.lock 25 | 26 | # Subproject ignores 27 | /rpc/target 28 | -------------------------------------------------------------------------------- /.pep8: -------------------------------------------------------------------------------- 1 | [pep8] 2 | ignore=W503 3 | exclude=build,docs,ECDSARecoverModule.py,poet0_enclave_simulator.py,poet1_enclave_simulator.py,*_pb2.py 4 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @grkvlt @dplumb94 @vaporos @peterschwarz 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | Code of Conduct Guidelines 2 | ========================== 3 | 4 | Please review the Hyperledger [Code of 5 | Conduct](https://tsc.hyperledger.org/code-of-conduct.html) before participating 6 | and abide by these community standards. 7 | 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Distributed Ledger 2 | 3 | This document covers how to report issues and contribute code. 4 | 5 | ## Topics 6 | 7 | * [Reporting Issues](#reporting-issues) 8 | * [Contributing Code](#contributing-code) 9 | 10 | # Reporting Issues 11 | 12 | Please refer to the article on [Issue Tracking](http://intelledger.github.io/community/issue_tracking.html) in the Sawtooth Lake documentation. 13 | 14 | # Contributing Code 15 | 16 | Distributed Ledger is Apache 2.0 licensed and accepts contributions via 17 | [GitHub](https://github.com/hyperledger/) pull requests. 18 | 19 | Please refer to the article on 20 | [Contributing](http://intelledger.github.io/community/contributing.html) 21 | in the Sawtooth Lake documentation for information on contributing, and the 22 | guidelines to use. -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | [workspace] 17 | members = ["cli", "rpc"] 18 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | ## Maintainers 2 | 3 | ### Active Maintainers 4 | | Name | GitHub | RocketChat | 5 | | --- | --- | --- | 6 | | Andrew Donald Kennedy | grkvlt | grkvlt | 7 | | Arun S M | arsulegai | arsulegai | 8 | | Darian Plumb | dplumb94 | dplumb | 9 | | Shawn Amundson | vaporos | amundson | 10 | | Peter Schwarz | peterschwarz | pschwarz | 11 | 12 | ### Retired Maintainers 13 | | Name | GitHub | RocketChat | 14 | | --- | --- | --- | 15 | | Adam Ludvik | aludvik | adamludvik | 16 | | Kenneth Koski | knkski | knkski | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Hyperledger Sawtooth - Seth 2 | ------------- 3 | 4 | This project is an Ethereum-compatible transaction family for the Hyperledger 5 | Sawtooth platform. 6 | 7 | The primary goal of the Sawtooth-Ethereum integration project, affectionately 8 | dubbed "Seth", is to add support for running Ethereum Virtual Machine smart 9 | contracts to the Hyperledger Sawtooth platform. In order to make this possible, 10 | the Hyperledger Sawtooth project worked with the 11 | [Hyperledger Burrow](https://github.com/hyperledger/burrow) project to integrate 12 | their EVM implementation, the Burrow EVM, into with the Hyperledger Sawtooth 13 | platform. 14 | 15 | Documentation 16 | ------------- 17 | 18 | Documentation for how to run and extend Sawtooth is available here: 19 | https://sawtooth.hyperledger.org/docs/seth/releases/latest/introduction.html 20 | 21 | License 22 | ------- 23 | 24 | Hyperledger Sawtooth software is licensed under the [Apache License Version 2.0](LICENSE) software license. 25 | 26 | Hyperledger Sawtooth documentation in the [docs](docs) subdirectory is licensed under 27 | a Creative Commons Attribution 4.0 International License. You may obtain a copy of the 28 | license at: http://creativecommons.org/licenses/by/4.0/. 29 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.2.4 2 | -------------------------------------------------------------------------------- /bin/authorize-cicd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ -z $1 || -z $2 ]] 4 | then 5 | echo "USAGE: $0 [user] [authlist]" 6 | exit 1 7 | fi 8 | 9 | authlist=$(cat $2 | grep user | sed 's#.*: \(.*$\)#\1#') 10 | for user in $authlist 11 | do 12 | if [[ $user == $1 ]] 13 | then 14 | echo "SUCCESS: User '$1' authorized" 15 | exit 0 16 | fi 17 | done 18 | 19 | echo "FAILED: User '$1' not authorized." 20 | exit 1 21 | -------------------------------------------------------------------------------- /bin/generate_cli_output: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -e source/conf.py ]; then 4 | echo "Must be run from the sawtooth-seth repo docs directory." 1>&2 5 | exit 1 6 | fi 7 | 8 | function save_usage() { 9 | safe_string=$(echo "$*" | sed -e 's/[^A-Za-z0-9-]/_/g') 10 | filename="source/cli/output/${safe_string}_usage.out" 11 | if ! output=$("$@" -h); then 12 | exit 1 13 | fi 14 | echo "Generating: $filename" 15 | echo "$output" > "$filename" 16 | } 17 | 18 | export PATH=$PATH:$(pwd)/../bin 19 | mkdir -p source/cli/output 20 | 21 | save_usage seth 22 | save_usage seth init 23 | save_usage seth show 24 | save_usage seth account 25 | save_usage seth account import 26 | save_usage seth account list 27 | save_usage seth account create 28 | save_usage seth contract 29 | save_usage seth contract call 30 | save_usage seth contract create 31 | save_usage seth permissions 32 | save_usage seth permissions set 33 | 34 | save_usage seth-tp 35 | 36 | save_usage seth-rpc 37 | -------------------------------------------------------------------------------- /bin/get_version: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright 2016, 2017 Intel Corporation 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ------------------------------------------------------------------------------ 17 | 18 | import os 19 | import subprocess 20 | import sys 21 | 22 | top_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 23 | 24 | version_file = top_dir + "/VERSION" 25 | 26 | with open(version_file, 'r') as f: 27 | version_data = f.read().strip() 28 | 29 | 30 | def bump_version(version): 31 | (major, minor, patch) = version.split('.') 32 | if 'rc' in patch: 33 | parts = patch.split('rc') 34 | parts[1] = str(int(parts[1]) + 1) 35 | patch = "rc".join(parts) 36 | else: 37 | patch = str(int(patch) + 1) 38 | return ".".join([major, minor, patch]) 39 | 40 | 41 | def auto_version(default, strict): 42 | output = subprocess.check_output(['git', 'describe', '--dirty']) 43 | parts = output.decode('utf-8').strip().split('-', 3) 44 | parts[0] = parts[0][1:] # strip the leading 'v' 45 | if len(parts) > 1: 46 | parts[0] = bump_version(parts[0]) 47 | if default != parts[0]: 48 | msg = "VERSION file and (bumped?) git describe versions differ: " \ 49 | "{} != {}".format(default, parts[0]) 50 | if strict: 51 | print("ERROR: " + msg, file=sys.stderr) 52 | sys.exit(1) 53 | else: 54 | print("WARNING: " + msg, file=sys.stderr) 55 | print( 56 | "WARNING: using setup.py version {}".format(default), 57 | file=sys.stderr) 58 | parts[0] = default 59 | 60 | if len(parts) > 1: 61 | parts[0] = "-dev".join([parts[0], parts[1].replace("-", ".")]) 62 | if len(parts) == 4: 63 | parts[0] = parts[0] + "-" + parts[3] 64 | return parts[0] 65 | else: 66 | return parts[0] 67 | 68 | 69 | def version(default): 70 | if 'VERSION' in os.environ: 71 | if os.environ['VERSION'] == 'AUTO_STRICT': 72 | version = auto_version(default, strict=True) 73 | elif os.environ['VERSION'] == 'AUTO': 74 | version = auto_version(default, strict=False) 75 | else: 76 | version = os.environ['VERSION'] 77 | else: 78 | version = default + "-dev1" 79 | return version 80 | 81 | 82 | print(version(version_data)) 83 | -------------------------------------------------------------------------------- /bin/run_go_fmt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | top_dir=$(cd $(dirname $(dirname $0)) && pwd) 4 | 5 | cd $top_dir 6 | 7 | dirs=" 8 | $top_dir/processor/src/seth_tp 9 | $top_dir/processor/src/seth_tp/handler 10 | $top_dir/cli-go/src/seth_cli/cli 11 | $top_dir/cli-go/src/seth_cli/client 12 | $top_dir/common/src/common 13 | " 14 | 15 | exitcode=0 16 | for dir in $dirs 17 | do 18 | if [ -z $1 ] 19 | then 20 | changed=$(gofmt -l $(ls -1 $dir/*.go)) 21 | if [[ ! -z $changed ]] 22 | then 23 | echo "Incorrect formatting: $dir" 24 | exitcode=1 25 | fi 26 | else 27 | gofmt -w -l $(ls -1 $dir/*.go) 28 | fi 29 | done 30 | if [ $exitcode -ne 0 ] 31 | then 32 | echo "Do 'run_go_fmt fix' to fix" 33 | fi 34 | exit $exitcode 35 | -------------------------------------------------------------------------------- /bin/run_tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2017 Intel Corporation 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ------------------------------------------------------------------------------ 17 | 18 | 19 | # Exit on non-zero exit code from subcommand 20 | set -eux 21 | 22 | export PATH=$PATH:$(cd $(dirname $0) ; pwd) 23 | 24 | docker-compose build seth-rpc seth-cli seth-cli-go 25 | 26 | docker run --rm sawtooth-seth-rpc:${ISOLATION_ID:-latest} cargo test 27 | docker run --rm sawtooth-seth-cli:${ISOLATION_ID:-latest} cargo test 28 | 29 | run_docker_test ./tests/unit_seth.yaml 30 | run_docker_test seth_client_test 31 | run_docker_test seth_chaining_test 32 | run_docker_test seth_intkey_test 33 | run_docker_test seth_blockhash_test 34 | run_docker_test seth_blocknum_test 35 | run_docker_test seth_timestamp_test 36 | run_docker_test seth_perm_test 37 | run_docker_test ./rpc/comp_seth_rpc.yaml 38 | -------------------------------------------------------------------------------- /bin/test-entrypoint: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # The rest api may be slow to start up, and our tests are quick to 4 | # start up. The tests may then fail when attempting to connect to 5 | # the rest api. This is a convenience script that waits for the 6 | # rest api to be up to the point where it can accept http connections, 7 | # and then runs the command passed in to it. Fails after 10 attempts. 8 | # 9 | # Example usage: 10 | # 11 | # test-entrypoint go test foo.go 12 | 13 | echo "Waiting for rest-api to start up." 14 | 15 | # Adapted from https://stackoverflow.com/a/50055449 16 | timeout 10 bash -c 'until printf \"\" 2>>/dev/null >>/dev/tcp/rest-api/8080; do sleep 1; done' || { 17 | echo 'The rest-api took too long to start up!'; 18 | exit 1 19 | } 20 | 21 | echo "rest-api is up, running tests." 22 | 23 | # Run the given command 24 | $@ 25 | -------------------------------------------------------------------------------- /ci/sawtooth-seth-cli: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | # Description: 17 | # Builds an image with the Sawtooth Seth CLI package installed from 18 | # the Sawtooth Package Repository. 19 | 20 | FROM ubuntu:bionic 21 | 22 | RUN apt-get update \ 23 | && apt-get install gnupg -y 24 | 25 | LABEL "install-type"="repo" 26 | 27 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/chime/stable bionic universe" >> /etc/apt/sources.list \ 28 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 29 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 30 | && apt-get update \ 31 | && apt-get install -y -q \ 32 | sawtooth-seth-cli \ 33 | && apt-get clean \ 34 | && rm -rf /var/lib/apt/lists/* 35 | 36 | CMD ["seth"] 37 | -------------------------------------------------------------------------------- /ci/sawtooth-seth-cli-go: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | # Description: 17 | # Builds an image with the Sawtooth Seth CLI (Go) package installed from 18 | # the Sawtooth Package Repository. 19 | 20 | FROM ubuntu:bionic 21 | 22 | RUN apt-get update \ 23 | && apt-get install gnupg -y 24 | 25 | LABEL "install-type"="repo" 26 | 27 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/chime/stable bionic universe" >> /etc/apt/sources.list \ 28 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 29 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 30 | && apt-get update \ 31 | && apt-get install -y -q \ 32 | sawtooth-seth-cli-go \ 33 | && apt-get clean \ 34 | && rm -rf /var/lib/apt/lists/* 35 | 36 | CMD ["seth"] 37 | -------------------------------------------------------------------------------- /ci/sawtooth-seth-rpc: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | # Description: 17 | # Builds an image with the Sawtooth Seth RPC package installed from 18 | # the Sawtooth Package Repository. 19 | 20 | FROM ubuntu:bionic 21 | 22 | RUN apt-get update \ 23 | && apt-get install gnupg -y 24 | 25 | LABEL "install-type"="repo" 26 | 27 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/chime/stable bionic universe" >> /etc/apt/sources.list \ 28 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 29 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 30 | && apt-get update \ 31 | && apt-get install -y -q \ 32 | sawtooth-seth-rpc \ 33 | && apt-get clean \ 34 | && rm -rf /var/lib/apt/lists/* 35 | 36 | EXPOSE 3030/tcp 37 | 38 | CMD ["seth-rpc", "-vv"] 39 | -------------------------------------------------------------------------------- /ci/sawtooth-seth-tp: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | # Description: 17 | # Builds an image with the Sawtooth Seth TP package installed from 18 | # the Sawtooth Package Repository. 19 | 20 | FROM ubuntu:bionic 21 | 22 | RUN apt-get update \ 23 | && apt-get install gnupg -y 24 | 25 | LABEL "install-type"="repo" 26 | 27 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/chime/stable bionic universe" >> /etc/apt/sources.list \ 28 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 29 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 30 | && apt-get update \ 31 | && apt-get install -y -q \ 32 | sawtooth-seth-tp \ 33 | && apt-get clean \ 34 | && rm -rf /var/lib/apt/lists/* 35 | 36 | EXPOSE 4004/tcp 37 | 38 | CMD ["seth-tp", "-vv"] 39 | -------------------------------------------------------------------------------- /cli-go/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | FROM ubuntu:bionic 17 | 18 | RUN apt-get update \ 19 | && apt-get install gnupg -y 20 | 21 | ENV GOPATH=/project/sawtooth-seth/cli-go 22 | ENV PATH=$PATH:/project/sawtooth-seth/cli-go/bin:/project/sawtooth-seth/bin:/usr/lib/go-1.11/bin 23 | 24 | RUN \ 25 | if [ ! -z $HTTP_PROXY ] && [ -z $http_proxy ]; then \ 26 | http_proxy=$HTTP_PROXY; \ 27 | fi; \ 28 | if [ ! -z $HTTPS_PROXY ] && [ -z $https_proxy ]; then \ 29 | https_proxy=$HTTPS_PROXY; \ 30 | fi 31 | 32 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 33 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 34 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 308C15A29AD198E9 \ 35 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 308C15A29AD198E9) \ 36 | && echo 'deb http://repo.sawtooth.me/ubuntu/nightly bionic universe' >> /etc/apt/sources.list \ 37 | && echo 'deb http://ppa.launchpad.net/gophers/archive/ubuntu bionic main' >> /etc/apt/sources.list \ 38 | && apt-get update \ 39 | && apt-get install -y -q \ 40 | curl \ 41 | git \ 42 | golang-1.11-go \ 43 | libssl-dev \ 44 | libzmq3-dev \ 45 | openssl \ 46 | python3 \ 47 | python3-grpcio-tools \ 48 | python3-sawtooth-cli \ 49 | software-properties-common \ 50 | && add-apt-repository -k hkp://p80.pool.sks-keyservers.net:80 ppa:ethereum/ethereum \ 51 | && apt-get update \ 52 | && apt-get install -y -q \ 53 | solc \ 54 | && curl -s -S -o /tmp/setup-node.sh https://deb.nodesource.com/setup_6.x \ 55 | && chmod 755 /tmp/setup-node.sh \ 56 | && /tmp/setup-node.sh \ 57 | && apt-get install nodejs npm -y -q \ 58 | && rm /tmp/setup-node.sh \ 59 | && apt-get clean \ 60 | && rm -rf /var/lib/apt/lists/* 61 | 62 | RUN \ 63 | if [ ! -z $http_proxy ]; then \ 64 | npm config set proxy $http_proxy; \ 65 | git config --global http.proxy $http_proxy; \ 66 | fi; \ 67 | if [ ! -z $https_proxy ]; then \ 68 | npm config set https-proxy $https_proxy; \ 69 | git config --global https.proxy $https_proxy; \ 70 | fi 71 | 72 | RUN git config --global url."https://".insteadOf git:// 73 | 74 | RUN go get -u \ 75 | github.com/btcsuite/btcd/btcec \ 76 | github.com/golang/mock/gomock \ 77 | github.com/golang/mock/mockgen \ 78 | github.com/golang/protobuf/proto \ 79 | github.com/golang/protobuf/protoc-gen-go \ 80 | github.com/jessevdk/go-flags \ 81 | github.com/pebbe/zmq4 \ 82 | github.com/pelletier/go-toml \ 83 | github.com/satori/go.uuid \ 84 | golang.org/x/crypto/ssh/terminal 85 | 86 | RUN git clone https://github.com/knkski/burrow.git $GOPATH/src/github.com/hyperledger/burrow 87 | 88 | RUN go get github.com/hyperledger/sawtooth-sdk-go 89 | 90 | RUN npm install \ 91 | ethereumjs-abi \ 92 | web3 93 | 94 | COPY . /project/sawtooth-seth 95 | 96 | RUN seth-protogen go 97 | 98 | WORKDIR $GOPATH/src/seth_cli/cli 99 | ENV GOPATH=$GOPATH/src/github.com/hyperledger/sawtooth-sdk-go:$GOPATH:/project/sawtooth-seth/burrow:/project/sawtooth-seth/common 100 | RUN go build -o /project/sawtooth-seth/cli-go/bin/seth 101 | -------------------------------------------------------------------------------- /cli-go/packaging/ubuntu/changelog: -------------------------------------------------------------------------------- 1 | sawtooth-seth-cli (0.2.0) unstable; urgency=low 2 | 3 | * change data here 4 | 5 | -- Hyperledger Sawtooth 6 | -------------------------------------------------------------------------------- /cli-go/packaging/ubuntu/control: -------------------------------------------------------------------------------- 1 | Source: sawtooth-seth-cli 2 | Maintainer: Hyperledger Sawtooth 3 | Section: go 4 | Priority: optional 5 | Standards-Version: 3.9.6 6 | Homepage: https://github.com/hyperledger/sawtooth-seth 7 | Package: sawtooth-seth-cli 8 | Architecture: all 9 | Depends: libssl-dev 10 | Description: Sawtooth Seth CLI 11 | Version: 0.2.0 12 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/account.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | "os" 24 | ) 25 | 26 | type Account struct { 27 | Subs []Command `no-flag:"true"` 28 | Cmd *flags.Command `no-flag:"true"` 29 | } 30 | 31 | func (args *Account) Name() string { 32 | return "account" 33 | } 34 | 35 | func (args *Account) Register(parent *flags.Command) error { 36 | var err error 37 | args.Cmd, err = parent.AddCommand(args.Name(), "Manage seth accounts", "", args) 38 | 39 | // Add sub-commands 40 | args.Subs = []Command{ 41 | &AccountImport{}, 42 | &AccountList{}, 43 | &AccountCreate{}, 44 | } 45 | for _, sub := range args.Subs { 46 | err := sub.Register(args.Cmd) 47 | if err != nil { 48 | logger.Errorf("Couldn't register command %v: %v", sub.Name(), err) 49 | os.Exit(1) 50 | } 51 | } 52 | 53 | return err 54 | } 55 | 56 | func (args *Account) Run(config *Config) error { 57 | name := args.Cmd.Active.Name 58 | for _, sub := range args.Subs { 59 | if sub.Name() == name { 60 | err := sub.Run(config) 61 | if err != nil { 62 | fmt.Printf("Error: %v\n", err) 63 | os.Exit(1) 64 | } 65 | return nil 66 | } 67 | } 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/account_create.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | . "protobuf/seth_pb2" 24 | "seth_cli/client" 25 | "strconv" 26 | ) 27 | 28 | type AccountCreate struct { 29 | Moderator string `short:"m" long:"moderator" description:"Alias of another account to be used to create the account"` 30 | Permissions string `short:"p" long:"permissions" description:"Permissions for new account; see 'seth permissions -h' for more info"` 31 | Nonce string `short:"n" long:"nonce" description:"Current nonce of the moderator account; if not passed, the current value will be retrieved"` 32 | Wait int `short:"w" long:"wait" description:"Number of seconds Seth client will wait for transaction to be committed, if flag passed, default is 60 seconds; if no flag passed, do not wait" optional:"true" optional-value:"60"` 33 | Positional struct { 34 | Alias string `positional-arg-name:"alias" required:"true" description:"Alias of the imported key associated with the account to be created"` 35 | } `positional-args:"true"` 36 | } 37 | 38 | func (args *AccountCreate) Name() string { 39 | return "create" 40 | } 41 | 42 | func (args *AccountCreate) Register(parent *flags.Command) error { 43 | _, err := parent.AddCommand( 44 | args.Name(), "Create a new externally owned account", 45 | "", args, 46 | ) 47 | if err != nil { 48 | return err 49 | } 50 | return nil 51 | } 52 | 53 | func (args *AccountCreate) Run(config *Config) error { 54 | client := client.New(config.Url) 55 | 56 | priv, err := LoadKey(args.Positional.Alias) 57 | if err != nil { 58 | return err 59 | } 60 | 61 | var ( 62 | mod []byte 63 | perms *EvmPermissions 64 | ) 65 | 66 | if args.Moderator != "" { 67 | mod, err = LoadKey(args.Moderator) 68 | if err != nil { 69 | return err 70 | } 71 | } 72 | 73 | if args.Permissions != "" { 74 | perms, err = ParsePermissions(args.Permissions) 75 | if err != nil { 76 | return fmt.Errorf("Invalid permissions: %v", err) 77 | } 78 | } 79 | 80 | var nonce uint64 81 | if args.Nonce == "" { 82 | nonce, err = client.LookupAccountNonce(priv) 83 | if err != nil { 84 | return err 85 | } 86 | } else { 87 | nonce, err = strconv.ParseUint(args.Nonce, 10, 64) 88 | if err != nil { 89 | return fmt.Errorf("Invalid nonce `%v`: ", args.Nonce, err) 90 | } 91 | } 92 | 93 | if args.Wait < 0 { 94 | return fmt.Errorf("Invalid wait specified: %v. Must be a positive integer", args.Wait) 95 | } 96 | 97 | clientResult, err := client.CreateExternalAccount(priv, mod, perms, nonce, args.Wait) 98 | if err != nil { 99 | return fmt.Errorf("Problem submitting account creation transaction: %v", err) 100 | } 101 | 102 | if args.Wait > 0 { 103 | fmt.Printf("Account created\n") 104 | } else { 105 | fmt.Printf("Transaction submitted to create account\n") 106 | } 107 | info, err := clientResult.MarshalJSON() 108 | if err != nil { 109 | return fmt.Errorf("Error displaying receipt: %s", err.Error()) 110 | } 111 | fmt.Println("Transaction Receipt: ", string(info)) 112 | 113 | return nil 114 | } 115 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/account_import.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | "io/ioutil" 24 | "path" 25 | ) 26 | 27 | type AccountImport struct { 28 | Force bool `short:"f" long:"force" description:"Overwrite key with the same alias if it exists"` 29 | Positional struct { 30 | KeyFile string `positional-arg-name:"key-file" required:"true" description:"Path to the file that contains the private key to import"` 31 | Alias string `positional-arg-name:"alias" required:"true" description:"Alias to assign the private key"` 32 | } `positional-args:"true"` 33 | } 34 | 35 | func (args *AccountImport) Name() string { 36 | return "import" 37 | } 38 | func (args *AccountImport) Register(parent *flags.Command) error { 39 | _, err := parent.AddCommand( 40 | args.Name(), "Import the private and create an alias for later reference", 41 | "", args, 42 | ) 43 | if err != nil { 44 | return err 45 | } 46 | return nil 47 | } 48 | func (args *AccountImport) Run(*Config) error { 49 | keyFilePath := args.Positional.KeyFile 50 | alias := args.Positional.Alias 51 | if !pathExists(keyFilePath) { 52 | return fmt.Errorf("File does not exist %v", keyFilePath) 53 | } 54 | 55 | buf, err := ioutil.ReadFile(keyFilePath) 56 | if err != nil { 57 | return fmt.Errorf("Couldn't load key from file %v: %v", keyFilePath, err) 58 | } 59 | 60 | if match, _ := path.Match("*.pem", keyFilePath); match { 61 | err = SaveKey(alias, string(buf), "pem", args.Force) 62 | } else { 63 | err = SaveKey(alias, string(buf), "", args.Force) 64 | } 65 | if err != nil { 66 | return fmt.Errorf("Failed to import key: %v", err) 67 | } 68 | 69 | fmt.Printf("Key at %v imported with alias %v\n", keyFilePath, alias) 70 | return nil 71 | } 72 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/account_list.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | . "common" 22 | "fmt" 23 | "github.com/jessevdk/go-flags" 24 | "io/ioutil" 25 | "path" 26 | ) 27 | 28 | type AccountList struct{} 29 | 30 | func (args *AccountList) Name() string { 31 | return "list" 32 | } 33 | func (args *AccountList) Register(parent *flags.Command) error { 34 | _, err := parent.AddCommand( 35 | args.Name(), "List all imported accounts as \"alias: address\"", 36 | "", args, 37 | ) 38 | return err 39 | } 40 | func (args *AccountList) Run(*Config) error { 41 | keyDir := getKeyDir() 42 | if !pathExists(keyDir) { 43 | fmt.Println("No accounts have been imported.") 44 | return nil 45 | } 46 | 47 | keys, err := ioutil.ReadDir(keyDir) 48 | if err != nil { 49 | fmt.Errorf("Couldn't list keys: %v", err) 50 | } 51 | 52 | aliases := make([]string, 0) 53 | addrs := make([]string, 0) 54 | for _, keyfile := range keys { 55 | keyname := keyfile.Name() 56 | var alias string 57 | if match, _ := path.Match("*.wif", keyname); match { 58 | alias = keyname[:len(keyname)-4] 59 | } else if match, _ := path.Match("*.pem", keyname); match { 60 | alias = keyname[:len(keyname)-4] 61 | } else { 62 | continue 63 | } 64 | priv, err := LoadKey(alias) 65 | if err != nil { 66 | fmt.Printf("Couldn't load key with alias %v: %v\n", alias, err) 67 | continue 68 | } 69 | addr, err := PrivToEvmAddr(priv) 70 | if err != nil { 71 | fmt.Printf( 72 | "Failed to derive address from key with alias %v: %v\n", alias, err, 73 | ) 74 | continue 75 | } 76 | aliases = append(aliases, alias) 77 | addrs = append(addrs, addr.String()) 78 | } 79 | for i, _ := range aliases { 80 | fmt.Printf("%v: %v\n", aliases[i], addrs[i]) 81 | } 82 | 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/contract.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | "os" 24 | ) 25 | 26 | type Contract struct { 27 | Subs []Command `no-flag:"true"` 28 | Cmd *flags.Command `no-flag:"true"` 29 | } 30 | 31 | func (args *Contract) Name() string { 32 | return "contract" 33 | } 34 | 35 | func (args *Contract) Register(parent *flags.Command) error { 36 | var err error 37 | args.Cmd, err = parent.AddCommand(args.Name(), "Deploy and execute contracts", "", args) 38 | 39 | // Add sub-commands 40 | args.Subs = []Command{ 41 | &ContractCreate{}, 42 | &ContractCall{}, 43 | &ContractList{}, 44 | } 45 | for _, sub := range args.Subs { 46 | err := sub.Register(args.Cmd) 47 | if err != nil { 48 | logger.Errorf("Couldn't register command %v: %v", sub.Name(), err) 49 | os.Exit(1) 50 | } 51 | } 52 | 53 | return err 54 | } 55 | 56 | func (args *Contract) Run(config *Config) error { 57 | name := args.Cmd.Active.Name 58 | for _, sub := range args.Subs { 59 | if sub.Name() == name { 60 | err := sub.Run(config) 61 | if err != nil { 62 | fmt.Printf("Error: %v\n", err) 63 | os.Exit(1) 64 | } 65 | return nil 66 | } 67 | } 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/contract_call.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "encoding/hex" 22 | "fmt" 23 | "github.com/jessevdk/go-flags" 24 | "seth_cli/client" 25 | "strconv" 26 | ) 27 | 28 | type ContractCall struct { 29 | Positional struct { 30 | Alias string `positional-arg-name:"alias" required:"true" description:"Alias of the imported key associated with the contract to be created"` 31 | Address string `positional-arg-name:"address" description:"Address of contract to call"` 32 | Data string `positional-arg-name:"data" required:"true" description:"Input data to pass to contract when called; must conform to contract ABI"` 33 | } `positional-args:"true"` 34 | Gas uint64 `short:"g" long:"gas" description:"Gas limit for contract creation" default:"90000"` 35 | Nonce string `short:"n" long:"nonce" description:"Current nonce of moderator account"` 36 | Wait int `short:"w" long:"wait" description:"Number of seconds Seth client will wait for transaction to be committed; if flag passed, default is 60 seconds; if no flag passed, do not wait" optional:"true" optional-value:"60"` 37 | Chaining bool `short:"c" long:"chaining-enabled" description:"If true, enables contract chaining" defalt:"False"` 38 | } 39 | 40 | func (args *ContractCall) Name() string { 41 | return "call" 42 | } 43 | 44 | func (args *ContractCall) Register(parent *flags.Command) error { 45 | _, err := parent.AddCommand( 46 | args.Name(), "Execute a deployed contract account", 47 | "", args, 48 | ) 49 | if err != nil { 50 | return err 51 | } 52 | return nil 53 | } 54 | 55 | func (args *ContractCall) Run(config *Config) error { 56 | client := client.New(config.Url) 57 | 58 | priv, err := LoadKey(args.Positional.Alias) 59 | if err != nil { 60 | return err 61 | } 62 | 63 | data, err := hex.DecodeString(args.Positional.Data) 64 | if err != nil { 65 | return fmt.Errorf("Invalid contract input data: %v", err) 66 | } 67 | 68 | addr, err := hex.DecodeString(args.Positional.Address) 69 | if err != nil { 70 | return fmt.Errorf("Invalid address: %v", err) 71 | } 72 | 73 | if args.Wait < 0 { 74 | return fmt.Errorf("Invalid wait specified: %v. Must be a positive integer", args.Wait) 75 | } 76 | 77 | var nonce uint64 78 | if args.Nonce == "" { 79 | nonce, err = client.LookupAccountNonce(priv) 80 | if err != nil { 81 | return err 82 | } 83 | } else { 84 | nonce, err = strconv.ParseUint(args.Nonce, 10, 64) 85 | if err != nil { 86 | return fmt.Errorf("Invalid nonce `%v`: ", args.Nonce, err) 87 | } 88 | } 89 | 90 | clientResult, err := client.MessageCall(priv, addr, data, nonce, args.Gas, args.Wait, args.Chaining) 91 | if err != nil { 92 | return fmt.Errorf("Problem submitting account creation transaction: %v", err) 93 | } 94 | 95 | if args.Wait > 0 { 96 | fmt.Printf("Contract called\n") 97 | } else { 98 | fmt.Printf("Transaction submitted to call contract\n") 99 | } 100 | info, err := clientResult.MarshalJSON() 101 | if err != nil { 102 | return fmt.Errorf("Error displaying receipt: %s", err.Error()) 103 | } 104 | fmt.Println("Transaction Receipt: ", string(info)) 105 | 106 | return nil 107 | } 108 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/contract_create.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "encoding/hex" 22 | "fmt" 23 | "github.com/jessevdk/go-flags" 24 | . "protobuf/seth_pb2" 25 | "seth_cli/client" 26 | "strconv" 27 | ) 28 | 29 | type ContractCreate struct { 30 | Positional struct { 31 | Alias string `positional-arg-name:"alias" required:"true" description:"Alias of the imported key associated with the contract to be created"` 32 | Init string `positional-arg-name:"init" required:"true" description:"Initialization code to be executed on deployment"` 33 | } `positional-args:"true"` 34 | Permissions string `short:"p" long:"permissions" description:"Permissions for new account; see 'seth permissions -h' for more info"` 35 | Gas uint64 `short:"g" long:"gas" description:"Gas limit for contract creation" default:"90000"` 36 | Nonce string `short:"n" long:"nonce" description:"Current nonce of the moderator account; if not passed, the current value will be retrieved"` 37 | Wait int `short:"w" long:"wait" description:"Number of seconds Seth client will wait for transaction to be committed; if flag passed, default is 60 seconds; if no flag passed, do not wait" optional:"true" optional-value:"60"` 38 | } 39 | 40 | func (args *ContractCreate) Name() string { 41 | return "create" 42 | } 43 | 44 | func (args *ContractCreate) Register(parent *flags.Command) error { 45 | _, err := parent.AddCommand( 46 | args.Name(), "Deploy a new contract account", 47 | "", args, 48 | ) 49 | if err != nil { 50 | return err 51 | } 52 | return nil 53 | } 54 | 55 | func (args *ContractCreate) Run(config *Config) error { 56 | client := client.New(config.Url) 57 | 58 | priv, err := LoadKey(args.Positional.Alias) 59 | if err != nil { 60 | return err 61 | } 62 | 63 | init, err := hex.DecodeString(args.Positional.Init) 64 | if err != nil { 65 | return fmt.Errorf("Invalid initialization code: %v", err) 66 | } 67 | 68 | var perms *EvmPermissions 69 | if args.Permissions != "" { 70 | perms, err = ParsePermissions(args.Permissions) 71 | if err != nil { 72 | return fmt.Errorf("Invalid permissions: %v", err) 73 | } 74 | } 75 | 76 | if args.Wait < 0 { 77 | return fmt.Errorf("Invalid wait specified: %v. Must be a positive integer", args.Wait) 78 | } 79 | 80 | var nonce uint64 81 | if args.Nonce == "" { 82 | nonce, err = client.LookupAccountNonce(priv) 83 | if err != nil { 84 | return err 85 | } 86 | } else { 87 | nonce, err = strconv.ParseUint(args.Nonce, 10, 64) 88 | if err != nil { 89 | return fmt.Errorf("Invalid nonce `%v`: ", args.Nonce, err) 90 | } 91 | } 92 | 93 | clientResult, err := client.CreateContractAccount(priv, init, perms, nonce, args.Gas, args.Wait) 94 | if err != nil { 95 | return fmt.Errorf("Problem submitting account creation transaction: %v", err) 96 | } 97 | 98 | if args.Wait > 0 { 99 | fmt.Printf("Contract created\n") 100 | } else { 101 | fmt.Printf("Transaction submitted to create contract\n") 102 | } 103 | info, err := clientResult.MarshalJSON() 104 | if err != nil { 105 | return fmt.Errorf("Error displaying receipt: %s", err.Error()) 106 | } 107 | fmt.Println("Transaction Receipt: ", string(info)) 108 | 109 | return nil 110 | } 111 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/contract_list.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | . "common" 22 | "fmt" 23 | "github.com/jessevdk/go-flags" 24 | "seth_cli/client" 25 | ) 26 | 27 | type ContractList struct { 28 | Positional struct { 29 | Alias string `positional-arg-name:"alias" required:"true" description:"Alias of the imported key associated with the contract to be created"` 30 | } `positional-args:"true"` 31 | } 32 | 33 | func (args *ContractList) Name() string { 34 | return "list" 35 | } 36 | 37 | func (args *ContractList) Register(parent *flags.Command) error { 38 | help := `List the addresses of all contracts that could have been created based on the current nonce of the account owned by the private key with the given alias. Note that not all addresses may be valid, since the nonce increments whenever a transaction is sent from an account` 39 | _, err := parent.AddCommand( 40 | args.Name(), help, 41 | "", args, 42 | ) 43 | if err != nil { 44 | return err 45 | } 46 | return nil 47 | } 48 | 49 | func (args *ContractList) Run(config *Config) error { 50 | client := client.New(config.Url) 51 | 52 | priv, err := LoadKey(args.Positional.Alias) 53 | if err != nil { 54 | return err 55 | } 56 | 57 | nonce, err := client.LookupAccountNonce(priv) 58 | if err != nil { 59 | return err 60 | } 61 | 62 | addr, err := PrivToEvmAddr(priv) 63 | if err != nil { 64 | return err 65 | } 66 | 67 | fmt.Printf( 68 | "Address of contracts by nonce for account with alias `%v`\n", 69 | args.Positional.Alias, 70 | ) 71 | var i uint64 72 | for i = 1; i < nonce; i++ { 73 | var derived = addr.Derive(i) 74 | entry, err := client.Get(derived.Bytes()) 75 | 76 | // Abort on error 77 | if err != nil { 78 | fmt.Printf("Encountered error while listing contracts: %s", err) 79 | break 80 | } 81 | 82 | // Skip non-existent contracts 83 | if entry == nil { 84 | continue 85 | } 86 | 87 | fmt.Printf("%v: %v\n", i, derived) 88 | } 89 | 90 | return nil 91 | } 92 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/init.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | ) 24 | 25 | type Init struct { 26 | Positional struct { 27 | Url string `positional-arg-name:"[url]"` 28 | } `positional-args:"true" required:"true"` 29 | } 30 | 31 | func (cmd *Init) Name() string { 32 | return "init" 33 | } 34 | 35 | func (cmd *Init) Register(parent *flags.Command) error { 36 | _, err := parent.AddCommand( 37 | "init", "Initialize seth to communicate with the given URL", "", cmd, 38 | ) 39 | return err 40 | } 41 | 42 | func (cmd *Init) Run(*Config) error { 43 | fmt.Printf("Initializing seth to communicate with %v\n", cmd.Positional.Url) 44 | 45 | err := SaveConfig(&Config{ 46 | Url: cmd.Positional.Url, 47 | }) 48 | 49 | if err != nil { 50 | return fmt.Errorf("Failed to initialize: %v", err) 51 | } 52 | 53 | return nil 54 | } 55 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/main.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/hyperledger/sawtooth-sdk-go/logging" 23 | "github.com/jessevdk/go-flags" 24 | "os" 25 | ) 26 | 27 | var logger *logging.Logger = logging.Get() 28 | 29 | // All subcommands implement this interface 30 | type Command interface { 31 | Register(*flags.Command) error 32 | Name() string 33 | Run(*Config) error 34 | } 35 | 36 | // Opts to the main command 37 | type MainOpts struct { 38 | Verbose []bool `short:"v" long:"verbose" description:"Set the log level"` 39 | } 40 | 41 | func main() { 42 | var opts MainOpts 43 | 44 | // Create top-level parser 45 | parser := flags.NewParser(&opts, flags.Default) 46 | parser.Command.Name = "seth" 47 | 48 | // Add sub-commands 49 | commands := []Command{ 50 | &Account{}, 51 | &Contract{}, 52 | &Show{}, 53 | &Init{}, 54 | &Permissions{}, 55 | } 56 | for _, cmd := range commands { 57 | err := cmd.Register(parser.Command) 58 | if err != nil { 59 | logger.Errorf("Couldn't register command %v: %v", cmd.Name(), err) 60 | os.Exit(1) 61 | } 62 | } 63 | 64 | // Parse the args 65 | remaining, err := parser.Parse() 66 | if e, ok := err.(*flags.Error); ok { 67 | if e.Type == flags.ErrHelp { 68 | return 69 | } else { 70 | os.Exit(1) 71 | } 72 | } 73 | 74 | if len(remaining) > 0 { 75 | fmt.Printf("Error: Unrecognized arguments passed: %v\n", remaining) 76 | os.Exit(2) 77 | } 78 | 79 | switch len(opts.Verbose) { 80 | case 2: 81 | logger.SetLevel(logging.DEBUG) 82 | case 1: 83 | logger.SetLevel(logging.INFO) 84 | default: 85 | logger.SetLevel(logging.WARN) 86 | } 87 | 88 | // If a sub-command was passed, run it 89 | if parser.Command.Active == nil { 90 | os.Exit(2) 91 | } 92 | 93 | config, err := LoadConfig() 94 | if err != nil { 95 | fmt.Println("Error: Failed to load config: %v", err) 96 | return 97 | } 98 | 99 | name := parser.Command.Active.Name 100 | for _, cmd := range commands { 101 | if cmd.Name() == name { 102 | err := cmd.Run(config) 103 | if err != nil { 104 | fmt.Printf("Error: %v\n", err) 105 | os.Exit(1) 106 | } 107 | return 108 | } 109 | } 110 | 111 | fmt.Println("Error: Command not found: %v", name) 112 | } 113 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/permissions_set.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "encoding/hex" 22 | "fmt" 23 | "github.com/jessevdk/go-flags" 24 | "seth_cli/client" 25 | "strconv" 26 | ) 27 | 28 | type PermissionsSet struct { 29 | Positional struct { 30 | Moderator string `positional-arg-name:"moderator" required:"true" description:"Alias of key to be used for modifying permissions"` 31 | } `positional-args:"true"` 32 | Address string `short:"a" long:"address" required:"true" description:"Address of account whose permissions are being changed; 'global' may be used to refer to the zero address"` 33 | Permissions string `short:"p" long:"permissions" required:"true" description:"New permissions for the account"` 34 | Nonce string `short:"n" long:"nonce" description:"Current nonce of the moderator account; If not passed, the current value will be retrieved"` 35 | Wait int `short:"w" long:"wait" description:"Number of seconds Seth client will wait for transaction to be committed; If flag passed, default is 60 seconds; If no flag passed, do not wait" optional:"true" optional-value:"60"` 36 | } 37 | 38 | func (args *PermissionsSet) Name() string { 39 | return "set" 40 | } 41 | 42 | func (args *PermissionsSet) Register(parent *flags.Command) error { 43 | _, err := parent.AddCommand( 44 | args.Name(), "Change the permissions of accounts", 45 | "See 'seth permissions -h' for more info.", args, 46 | ) 47 | return err 48 | } 49 | 50 | func (args *PermissionsSet) Run(config *Config) error { 51 | client := client.New(config.Url) 52 | mod, err := LoadKey(args.Positional.Moderator) 53 | if err != nil { 54 | return err 55 | } 56 | 57 | if args.Address == "global" { 58 | args.Address = "0000000000000000000000000000000000000000" 59 | } 60 | addr, err := hex.DecodeString(args.Address) 61 | if err != nil { 62 | return fmt.Errorf("Invalid address: %v", err) 63 | } 64 | 65 | perms, err := ParsePermissions(args.Permissions) 66 | if err != nil { 67 | return fmt.Errorf("Invalid permissions: %v", err) 68 | } 69 | 70 | if args.Wait < 0 { 71 | return fmt.Errorf("Invalid wait specified: %v. Must be a positive integer", args.Wait) 72 | } 73 | 74 | var nonce uint64 75 | if args.Nonce == "" { 76 | nonce, err = client.LookupAccountNonce(mod) 77 | if err != nil { 78 | return err 79 | } 80 | } else { 81 | nonce, err = strconv.ParseUint(args.Nonce, 10, 64) 82 | if err != nil { 83 | return fmt.Errorf("Invalid nonce `%v`: ", args.Nonce, err) 84 | } 85 | } 86 | 87 | err = client.SetPermissions(mod, addr, perms, nonce, args.Wait) 88 | if err != nil { 89 | return fmt.Errorf("Problem submitting transaction to change permissions: %v", err) 90 | } 91 | 92 | if args.Wait > 0 { 93 | fmt.Printf( 94 | "Permissions changed of %v\n", hex.EncodeToString(addr), 95 | ) 96 | } else { 97 | fmt.Printf( 98 | "Transaction submitted to change permissions of %v\n", hex.EncodeToString(addr), 99 | ) 100 | } 101 | 102 | return nil 103 | } 104 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/show.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | "os" 24 | ) 25 | 26 | type Show struct { 27 | Subs []Command `no-flag:"true"` 28 | Cmd *flags.Command `no-flag:"true"` 29 | } 30 | 31 | func (args *Show) Name() string { 32 | return "show" 33 | } 34 | 35 | func (args *Show) Register(parent *flags.Command) error { 36 | var err error 37 | args.Cmd, err = parent.AddCommand(args.Name(), "Show data associated with accounts and transactions", "", args) 38 | 39 | // Add sub-commands 40 | args.Subs = []Command{ 41 | &ShowAccount{}, 42 | &ShowEvents{}, 43 | &ShowReceipt{}, 44 | } 45 | for _, sub := range args.Subs { 46 | err := sub.Register(args.Cmd) 47 | if err != nil { 48 | logger.Errorf("Couldn't register command %v: %v", sub.Name(), err) 49 | os.Exit(1) 50 | } 51 | } 52 | 53 | return err 54 | } 55 | 56 | func (args *Show) Run(config *Config) error { 57 | name := args.Cmd.Active.Name 58 | for _, sub := range args.Subs { 59 | if sub.Name() == name { 60 | err := sub.Run(config) 61 | if err != nil { 62 | fmt.Printf("Error: %v\n", err) 63 | os.Exit(1) 64 | } 65 | return nil 66 | } 67 | } 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/show_account.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "encoding/hex" 22 | "fmt" 23 | "github.com/jessevdk/go-flags" 24 | . "protobuf/seth_pb2" 25 | "seth_cli/client" 26 | ) 27 | 28 | type ShowAccount struct { 29 | Positional struct { 30 | Address string `positional-arg-name:"address" description:"Address of account to show"` 31 | } `positional-args:"true" required:"true"` 32 | } 33 | 34 | func (args *ShowAccount) Name() string { 35 | return "account" 36 | } 37 | 38 | func (args *ShowAccount) Register(parent *flags.Command) error { 39 | _, err := parent.AddCommand(args.Name(), "Show all data associated with a given account", "", args) 40 | return err 41 | } 42 | 43 | func (args *ShowAccount) Run(config *Config) (err error) { 44 | client := client.New(config.Url) 45 | 46 | addr, err := hex.DecodeString(args.Positional.Address) 47 | if err != nil { 48 | return fmt.Errorf("Invalid address: %v", err) 49 | } 50 | 51 | entry, err := client.Get(addr) 52 | if err != nil { 53 | return fmt.Errorf("Couldn't get data at %v: %v", addr, err) 54 | } 55 | 56 | DisplayEntry(entry) 57 | 58 | return nil 59 | } 60 | 61 | func DisplayEntry(entry *EvmEntry) { 62 | if entry == nil { 63 | fmt.Println("Nothing at that address") 64 | return 65 | } 66 | 67 | acct := entry.GetAccount() 68 | 69 | if len(acct.GetAddress()) == 0 { 70 | fmt.Println("Account does not exist") 71 | return 72 | } 73 | 74 | addr := hex.EncodeToString(acct.GetAddress()) 75 | code := hex.EncodeToString(acct.GetCode()) 76 | 77 | fmt.Printf(` 78 | Address: %v 79 | Balance: %v 80 | Code : %v 81 | Nonce : %v 82 | `, addr, acct.GetBalance(), code, acct.GetNonce()) 83 | 84 | displayPermissions(acct.GetPermissions()) 85 | displayStorage(entry.GetStorage()) 86 | 87 | } 88 | 89 | func displayStorage(stg []*EvmStorage) { 90 | if stg == nil || len(stg) == 0 { 91 | fmt.Println("(No Storage Set)\n") 92 | return 93 | } 94 | 95 | fmt.Println("Storage:") 96 | for _, pair := range stg { 97 | key := hex.EncodeToString(pair.GetKey()) 98 | val := hex.EncodeToString(pair.GetValue()) 99 | fmt.Printf("%v -> %v\n", key, val) 100 | } 101 | } 102 | 103 | func displayPermissions(perms *EvmPermissions) { 104 | if perms == nil { 105 | fmt.Println("(No Permissions Set)\n") 106 | } 107 | 108 | fmt.Printf("Perms : %v\n", SerializePermissions(perms)) 109 | } 110 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/show_events.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | "seth_cli/client" 24 | ) 25 | 26 | type ShowEvents struct { 27 | Positional struct { 28 | TransactionID string `positional-arg-name:"txn-id" description:"Transaction ID of event list to show"` 29 | } `positional-args:"true" required:"true"` 30 | } 31 | 32 | func (args *ShowEvents) Name() string { 33 | return "events" 34 | } 35 | 36 | func (args *ShowEvents) Register(parent *flags.Command) error { 37 | _, err := parent.AddCommand(args.Name(), "Show events associated with a given transaction ID", "", args) 38 | return err 39 | } 40 | 41 | func (args *ShowEvents) Run(config *Config) (err error) { 42 | client := client.New(config.Url) 43 | 44 | clientResult, err := client.GetEvents(args.Positional.TransactionID) 45 | if err != nil { 46 | return err 47 | } 48 | if len(clientResult.Events) == 0 { 49 | fmt.Println("No events to show") 50 | } else { 51 | events, err := clientResult.MarshalJSON() 52 | if err != nil { 53 | return fmt.Errorf("Error displaying events: %s", err.Error()) 54 | } 55 | fmt.Println("Events: ", string(events)) 56 | } 57 | return nil 58 | } 59 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/cli/show_receipt.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | "seth_cli/client" 24 | ) 25 | 26 | type ShowReceipt struct { 27 | Positional struct { 28 | TransactionID string `positional-arg-name:"txn-id" description:"Transaction ID of receipt to show"` 29 | } `positional-args:"true" required:"true"` 30 | } 31 | 32 | func (args *ShowReceipt) Name() string { 33 | return "receipt" 34 | } 35 | 36 | func (args *ShowReceipt) Register(parent *flags.Command) error { 37 | _, err := parent.AddCommand(args.Name(), "Show receipt associated with a given transaction ID", "", args) 38 | return err 39 | } 40 | 41 | func (args *ShowReceipt) Run(config *Config) (err error) { 42 | client := client.New(config.Url) 43 | 44 | clientResult, err := client.GetSethReceipt(args.Positional.TransactionID) 45 | if err != nil { 46 | return err 47 | } 48 | 49 | receipt, err := clientResult.MarshalJSON() 50 | if err != nil { 51 | return err 52 | } 53 | fmt.Println("Seth Transaction Receipt: ", string(receipt)) 54 | 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /cli-go/src/seth_cli/client/response.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package client 19 | 20 | import ( 21 | "encoding/json" 22 | "fmt" 23 | "io/ioutil" 24 | "net/http" 25 | ) 26 | 27 | type RespBody struct { 28 | Data interface{} 29 | Link string 30 | Head string 31 | Error ErrorBody 32 | } 33 | 34 | func (r *RespBody) String() string { 35 | if r.Data == nil { 36 | return fmt.Sprintf(` 37 | Data: 38 | Link: %v 39 | Head: %v 40 | `, r.Link, r.Head) 41 | } 42 | return fmt.Sprintf(` 43 | Data: %v 44 | Link: %v 45 | Head: %v 46 | `, r.Data, r.Link, r.Head) 47 | } 48 | 49 | type ErrorBody struct { 50 | Code int 51 | Title string 52 | Message string 53 | } 54 | 55 | func (e *ErrorBody) String() string { 56 | return fmt.Sprintf(` 57 | Code : %v 58 | Title : %v 59 | Message : %v 60 | `, e.Code, e.Title, e.Message) 61 | } 62 | 63 | func (e *ErrorBody) Error() string { 64 | return e.String() 65 | } 66 | 67 | func ParseRespBody(resp *http.Response) (*RespBody, error) { 68 | defer resp.Body.Close() 69 | buf, err := ioutil.ReadAll(resp.Body) 70 | if err != nil { 71 | return nil, err 72 | } 73 | 74 | if len(buf) == 0 { 75 | return nil, fmt.Errorf("Nothing at that address") 76 | } 77 | 78 | return ParseBodyData(buf) 79 | 80 | } 81 | 82 | func ParseBodyData(buf []byte) (*RespBody, error) { 83 | body := &RespBody{} 84 | err := json.Unmarshal(buf, body) 85 | return body, err 86 | } 87 | 88 | type ReceiptRespBody struct { 89 | Data []TransactionReceipt 90 | Link string 91 | Head string 92 | Error ErrorBody 93 | } 94 | type TransactionReceipt struct { 95 | TransactionId string 96 | StateChanges []struct { 97 | Value string 98 | Type string 99 | Address string 100 | } 101 | Events []Event 102 | Data []string 103 | } 104 | type Event struct { 105 | EventType string `json:"event_type"` 106 | Attributes []struct { 107 | Key string 108 | Value string 109 | } 110 | Data string 111 | } 112 | 113 | func ParseReceiptBody(resp *http.Response) (*ReceiptRespBody, error) { 114 | defer resp.Body.Close() 115 | buf, err := ioutil.ReadAll(resp.Body) 116 | if err != nil { 117 | return nil, err 118 | } 119 | 120 | if len(buf) == 0 { 121 | return nil, fmt.Errorf("No receipts.") 122 | } 123 | 124 | return ParseReceiptBodyData(buf) 125 | } 126 | 127 | func ParseReceiptBodyData(buf []byte) (*ReceiptRespBody, error) { 128 | body := &ReceiptRespBody{} 129 | err := json.Unmarshal(buf, body) 130 | return body, err 131 | } 132 | -------------------------------------------------------------------------------- /cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | [package] 17 | name = "sawtooth-seth-cli" 18 | version = "0.2.4" 19 | authors = ["sawtooth"] 20 | 21 | [[bin]] 22 | name = "seth" 23 | path = "src/main.rs" 24 | 25 | [dependencies] 26 | clap = "2" 27 | config = "0.9" 28 | dirs = "2.0" 29 | failure = "0.1" 30 | jsonrpc-core = "12.0" 31 | reqwest = "0.9" 32 | serde = "1.0" 33 | serde_derive = "1.0" 34 | serde_json = "1.0" 35 | time = "0.1" 36 | tiny-keccak = "1.4" 37 | toml = "0.5" 38 | 39 | [build-dependencies] 40 | cc = "1.0" 41 | glob = "0.3" 42 | protoc-rust = "2.0" 43 | -------------------------------------------------------------------------------- /cli/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | FROM ubuntu:bionic 17 | 18 | RUN apt-get update \ 19 | && apt-get install gnupg -y 20 | 21 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 22 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 23 | && echo 'deb http://repo.sawtooth.me/ubuntu/nightly bionic universe' >> /etc/apt/sources.list \ 24 | && apt-get update \ 25 | && apt-get install -y -q \ 26 | curl \ 27 | gcc \ 28 | git \ 29 | libssl-dev \ 30 | libzmq3-dev \ 31 | openssl \ 32 | pkg-config \ 33 | python3 \ 34 | python3-grpcio-tools \ 35 | python3-sawtooth-cli \ 36 | unzip \ 37 | && curl -s -S -o /tmp/setup-node.sh https://deb.nodesource.com/setup_6.x \ 38 | && chmod 755 /tmp/setup-node.sh \ 39 | && /tmp/setup-node.sh \ 40 | && apt-get install nodejs -y -q \ 41 | && rm /tmp/setup-node.sh \ 42 | && apt-get clean \ 43 | && rm -rf /var/lib/apt/lists/* 44 | 45 | RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \ 46 | && unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \ 47 | && rm protoc-3.5.1-linux-x86_64.zip 48 | 49 | RUN curl https://sh.rustup.rs -sSf > /usr/bin/rustup-init \ 50 | && chmod +x /usr/bin/rustup-init \ 51 | && rustup-init -y 52 | 53 | ENV PATH=$PATH:/project/sawtooth-seth/bin:/root/.cargo/bin:/protoc3/bin \ 54 | CARGO_INCREMENTAL=0 55 | 56 | RUN rustup component add clippy && \ 57 | rustup component add rustfmt 58 | 59 | WORKDIR /project/sawtooth-seth/cli 60 | 61 | COPY bin/ /project/sawtooth-seth/bin 62 | COPY protos/ /project/sawtooth-seth/protos 63 | COPY cli/ /project/sawtooth-seth/cli 64 | COPY common/ /project/sawtooth-seth/common 65 | COPY tests/ /project/sawtooth-seth/tests 66 | 67 | RUN cargo build && cp ./target/debug/seth /project/sawtooth-seth/bin/seth 68 | -------------------------------------------------------------------------------- /cli/Dockerfile-installed-bionic: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # Copyright 2019 Cargill Incorporated 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ------------------------------------------------------------------------------ 16 | 17 | # -------------=== seth cli build ===------------- 18 | 19 | FROM ubuntu:bionic 20 | 21 | ENV VERSION=AUTO_STRICT 22 | 23 | RUN apt-get update \ 24 | && apt-get install gnupg -y 25 | 26 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 27 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 28 | && echo 'deb http://repo.sawtooth.me/ubuntu/nightly bionic universe' >> /etc/apt/sources.list \ 29 | && apt-get update \ 30 | && apt-get install -y -q \ 31 | curl \ 32 | gcc \ 33 | git \ 34 | libssl-dev \ 35 | libzmq3-dev \ 36 | openssl \ 37 | pkg-config \ 38 | python3 \ 39 | python3-grpcio-tools \ 40 | python3-sawtooth-cli \ 41 | unzip \ 42 | && curl -s -S -o /tmp/setup-node.sh https://deb.nodesource.com/setup_6.x \ 43 | && chmod 755 /tmp/setup-node.sh \ 44 | && /tmp/setup-node.sh \ 45 | && apt-get install nodejs -y -q \ 46 | && rm /tmp/setup-node.sh \ 47 | && apt-get clean \ 48 | && rm -rf /var/lib/apt/lists/* 49 | 50 | RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \ 51 | && unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \ 52 | && rm protoc-3.5.1-linux-x86_64.zip 53 | 54 | RUN curl https://sh.rustup.rs -sSf > /usr/bin/rustup-init \ 55 | && chmod +x /usr/bin/rustup-init \ 56 | && rustup-init -y 57 | 58 | ENV PATH=$PATH:/project/sawtooth-seth/bin:/root/.cargo/bin:/protoc3/bin \ 59 | CARGO_INCREMENTAL=0 60 | 61 | RUN /root/.cargo/bin/cargo install cargo-deb 62 | 63 | RUN rustup component add clippy-preview && \ 64 | rustup component add rustfmt-preview 65 | 66 | COPY . /project 67 | 68 | WORKDIR /project/cli 69 | 70 | RUN export VERSION=$(../bin/get_version) \ 71 | && sed -i -e s/version.*$/version\ =\ \"${VERSION}\"/ Cargo.toml \ 72 | && /root/.cargo/bin/cargo deb --deb-version $VERSION 73 | 74 | # -------------=== seth cli docker build ===------------- 75 | 76 | FROM ubuntu:bionic 77 | 78 | RUN mkdir /debs 79 | 80 | COPY --from=0 /project/target/debian/sawtooth-seth-cli_*amd64.deb /debs 81 | 82 | RUN apt-get update \ 83 | && dpkg -i /debs/sawtooth-seth-cli_*amd64.deb || true \ 84 | && apt-get -f -y install \ 85 | && apt-get clean \ 86 | && rm -rf /var/lib/apt/lists/* 87 | -------------------------------------------------------------------------------- /cli/Dockerfile-installed-xenial: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | FROM ubuntu:xenial 17 | 18 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 19 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 20 | && echo 'deb http://repo.sawtooth.me/ubuntu/bumper/stable xenial universe' >> /etc/apt/sources.list \ 21 | && apt-get update \ 22 | && apt-get install -y -q \ 23 | curl \ 24 | gcc \ 25 | git \ 26 | libssl-dev \ 27 | libzmq3-dev \ 28 | openssl \ 29 | pkg-config \ 30 | python3 \ 31 | python3-grpcio-tools=1.1.3-1 \ 32 | python3-sawtooth-cli \ 33 | unzip \ 34 | && curl -s -S -o /tmp/setup-node.sh https://deb.nodesource.com/setup_6.x \ 35 | && chmod 755 /tmp/setup-node.sh \ 36 | && /tmp/setup-node.sh \ 37 | && apt-get install nodejs -y -q \ 38 | && rm /tmp/setup-node.sh \ 39 | && apt-get clean \ 40 | && rm -rf /var/lib/apt/lists/* 41 | 42 | RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \ 43 | && unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \ 44 | && rm protoc-3.5.1-linux-x86_64.zip 45 | 46 | RUN curl https://sh.rustup.rs -sSf > /usr/bin/rustup-init \ 47 | && chmod +x /usr/bin/rustup-init \ 48 | && rustup-init -y 49 | 50 | ENV PATH=$PATH:/project/sawtooth-seth/bin:/root/.cargo/bin:/protoc3/bin \ 51 | CARGO_INCREMENTAL=0 52 | 53 | RUN rustup component add clippy-preview && \ 54 | rustup component add rustfmt-preview 55 | 56 | WORKDIR /project/sawtooth-seth/cli 57 | 58 | COPY bin/ /project/sawtooth-seth/bin 59 | COPY protos/ /project/sawtooth-seth/protos 60 | COPY cli/ /project/sawtooth-seth/cli 61 | COPY common/ /project/sawtooth-seth/common 62 | COPY tests/ /project/sawtooth-seth/tests 63 | 64 | RUN cargo build && cp ./target/debug/seth /project/sawtooth-seth/bin/seth 65 | 66 | RUN pkg_dir=/project/build/debs/ \ 67 | && CHANGELOG_DIR="debian/usr/share/doc/sawtooth-seth" \ 68 | && if [ -d "debian" ]; then rm -rf debian; fi \ 69 | && mkdir -p $pkg_dir \ 70 | && mkdir -p debian/DEBIAN \ 71 | && mkdir -p $CHANGELOG_DIR \ 72 | && cp packaging/ubuntu/* debian \ 73 | && cp debian/changelog $CHANGELOG_DIR \ 74 | && mv debian/changelog $CHANGELOG_DIR/changelog.Debian \ 75 | && gzip --best $CHANGELOG_DIR/changelog \ 76 | && gzip --best $CHANGELOG_DIR/changelog.Debian \ 77 | && mv debian/control debian/DEBIAN \ 78 | # && mv debian/postinst debian/DEBIAN \ 79 | && PACKAGENAME=$(awk '/^Package:/ { print $2 }' debian/DEBIAN/control) \ 80 | && PACKAGEVERSION=$(dpkg-parsechangelog -S version -l $CHANGELOG_DIR/changelog.gz) \ 81 | && PACKAGEARCH=$(dpkg-architecture -qDEB_BUILD_ARCH) \ 82 | && mkdir debian/usr/bin \ 83 | && cp -R /project/sawtooth-seth/bin/seth debian/usr/bin \ 84 | # && cp -R packaging/systemd/* debian/ \ 85 | && fakeroot dpkg-deb --build debian \ 86 | && mv debian.deb $pkg_dir/"${PACKAGENAME}_${PACKAGEVERSION}_${PACKAGEARCH}.deb" 87 | 88 | FROM ubuntu:xenial 89 | 90 | RUN mkdir /debs 91 | 92 | COPY --from=0 /project/build/debs/sawtooth-seth-cli_*amd64.deb /debs 93 | 94 | RUN apt-get update \ 95 | && apt-get install -y -q \ 96 | dpkg-dev \ 97 | && cd /debs \ 98 | && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz \ 99 | && echo "deb file:/debs ./" >> /etc/apt/sources.list \ 100 | && apt-get update \ 101 | && apt-get install sawtooth-seth-cli -y -q --allow-unauthenticated \ 102 | && apt-get clean \ 103 | && rm -rf /var/lib/apt/lists/* 104 | -------------------------------------------------------------------------------- /cli/packaging/ubuntu/changelog: -------------------------------------------------------------------------------- 1 | sawtooth-seth-cli (0.2.0) unstable; urgency=low 2 | 3 | * change data here 4 | 5 | -- Hyperledger Sawtooth 6 | -------------------------------------------------------------------------------- /cli/packaging/ubuntu/control: -------------------------------------------------------------------------------- 1 | Source: sawtooth-seth-cli 2 | Maintainer: Hyperledger Sawtooth 3 | Section: rust 4 | Priority: optional 5 | Standards-Version: 3.9.6 6 | Homepage: https://github.com/hyperledger/sawtooth-seth 7 | Package: sawtooth-seth-cli 8 | Architecture: all 9 | Description: Sawtooth Seth CLI 10 | Version: 0.2.0 11 | -------------------------------------------------------------------------------- /cli/src/cli/config.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | //! Initialize CLI configuration 19 | 20 | use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; 21 | use client::{Client, Settings}; 22 | use dirs; 23 | use failure::Error; 24 | use std::fs; 25 | use toml::to_string; 26 | 27 | /// Returns Clap configuration 28 | pub fn get_cli<'a, 'b>() -> App<'a, 'b> { 29 | SubCommand::with_name("config") 30 | .about("Manages seth config") 31 | .setting(AppSettings::SubcommandRequiredElseHelp) 32 | .subcommands(vec![SubCommand::with_name("init") 33 | .about("Initializes seth config") 34 | .args(&[Arg::with_name("url") 35 | .long("--url") 36 | .takes_value(true) 37 | .help("The URL of the JSON-RPC API")])]) 38 | } 39 | 40 | /// Handles parsing Clap CLI matches 41 | pub fn parse_cli<'a>(matches: (&'a str, Option<&'a ArgMatches>)) -> Result<(), Error> { 42 | match matches { 43 | ("init", Some(m)) => { 44 | let url = m.value_of("url"); 45 | 46 | do_init(url)?; 47 | } 48 | _ => unreachable!(), 49 | } 50 | 51 | Ok(()) 52 | } 53 | 54 | /// Initializes Seth CLI configuration file 55 | pub fn do_init(url: Option<&str>) -> Result<(), Error> { 56 | let client = Client::new()?; 57 | 58 | let settings = Settings { 59 | url: url 60 | .or_else(|| Some(&client.url)) 61 | .expect("Client URL must exist!") 62 | .into(), 63 | }; 64 | 65 | let toml = to_string(&settings)?; 66 | 67 | let mut settings_file = 68 | dirs::home_dir().ok_or_else(|| format_err!("Couldn't find home directory!"))?; 69 | 70 | settings_file.push(".sawtooth"); 71 | settings_file.push("seth-config.toml"); 72 | 73 | fs::write(settings_file, toml)?; 74 | 75 | Ok(()) 76 | } 77 | -------------------------------------------------------------------------------- /cli/src/cli/event.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | //! Show events for a transaction 19 | 20 | use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; 21 | use client::Client; 22 | use failure::Error; 23 | use serde_json::to_string_pretty; 24 | use types::TransactionReceipt; 25 | 26 | /// Returns Clap configuration 27 | pub fn get_cli<'a, 'b>() -> App<'a, 'b> { 28 | SubCommand::with_name("event") 29 | .about("Manages seth events") 30 | .setting(AppSettings::SubcommandRequiredElseHelp) 31 | .subcommands(vec![SubCommand::with_name("list") 32 | .about("Lists seth events") 33 | .args(&[Arg::with_name("txn-id") 34 | .required(true) 35 | .help("Which transaction to show events for")])]) 36 | } 37 | 38 | /// Handles parsing Clap CLI matches 39 | pub fn parse_cli<'a>(matches: (&'a str, Option<&'a ArgMatches>)) -> Result<(), Error> { 40 | let client = &::client::Client::new()?; 41 | 42 | match matches { 43 | ("list", Some(m)) => { 44 | let txn_id = m.value_of("txn-id").expect("Transaction ID is required!"); 45 | 46 | do_list(client, txn_id)?; 47 | } 48 | _ => unreachable!(), 49 | } 50 | 51 | Ok(()) 52 | } 53 | 54 | /// Lists events for the given transaction 55 | pub fn do_list(client: &Client, txn_id: &str) -> Result<(), Error> { 56 | let receipt: TransactionReceipt = 57 | client.send_rpc_transaction("eth_getTransactionReceipt", &vec![format!("0x{}", txn_id)])?; 58 | 59 | println!("{}", to_string_pretty(&json!(receipt.logs))?); 60 | 61 | Ok(()) 62 | } 63 | -------------------------------------------------------------------------------- /cli/src/cli/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | //! Functions that implement CLI functionality 19 | 20 | pub mod account; 21 | pub mod config; 22 | pub mod contract; 23 | pub mod event; 24 | pub mod permissions; 25 | pub mod receipt; 26 | -------------------------------------------------------------------------------- /cli/src/cli/receipt.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | //! Show receipts 19 | 20 | use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; 21 | use client::Client; 22 | use failure::Error; 23 | use serde_json::to_string_pretty; 24 | use types::TransactionReceipt; 25 | 26 | /// Returns Clap configuration 27 | pub fn get_cli<'a, 'b>() -> App<'a, 'b> { 28 | SubCommand::with_name("receipt") 29 | .about("Manages seth receipts") 30 | .setting(AppSettings::SubcommandRequiredElseHelp) 31 | .subcommands(vec![SubCommand::with_name("show") 32 | .about("Manages seth receipts") 33 | .args(&[Arg::with_name("txn-id") 34 | .required(true) 35 | .help("Transaction ID of receipt to show")])]) 36 | } 37 | 38 | /// Handles parsing Clap CLI matches 39 | pub fn parse_cli<'a>(matches: (&'a str, Option<&'a ArgMatches>)) -> Result<(), Error> { 40 | let client = &::client::Client::new()?; 41 | 42 | match matches { 43 | ("show", Some(m)) => { 44 | let txn_id = m.value_of("txn-id").expect("Transaction ID is required!"); 45 | 46 | do_show(client, txn_id)?; 47 | } 48 | _ => unreachable!(), 49 | } 50 | 51 | Ok(()) 52 | } 53 | 54 | /// Shows the receipt for the given transaction 55 | pub fn do_show(client: &Client, txn_id: &str) -> Result<(), Error> { 56 | let receipt: TransactionReceipt = 57 | client.send_rpc_transaction("eth_getTransactionReceipt", &vec![format!("0x{}", txn_id)])?; 58 | 59 | println!( 60 | "{}", 61 | to_string_pretty(&json!({ 62 | "GasUsed": u64::from_str_radix(&receipt.gas_used[2..], 16)?, 63 | "Address": receipt.contract_address, 64 | "ReturnValue": receipt.return_value, 65 | }))? 66 | ); 67 | 68 | Ok(()) 69 | } 70 | -------------------------------------------------------------------------------- /cli/src/types.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | //! Common Seth types 19 | 20 | /// Seth transaction log 21 | #[derive(Debug, Serialize, Deserialize)] 22 | #[serde(rename_all = "camelCase")] 23 | pub struct TransactionLog { 24 | pub removed: bool, 25 | pub log_index: String, 26 | pub transaction_index: String, 27 | pub transaction_hash: String, 28 | pub block_hash: String, 29 | pub block_number: String, 30 | pub address: String, 31 | pub data: String, 32 | pub topics: Vec, 33 | } 34 | 35 | /// Seth transaction receipt 36 | #[derive(Debug, Serialize, Deserialize)] 37 | #[serde(rename_all = "camelCase")] 38 | pub struct TransactionReceipt { 39 | pub transaction_hash: String, 40 | pub transaction_index: String, 41 | pub block_hash: String, 42 | pub block_number: String, 43 | pub cumulative_gas_used: String, 44 | pub gas_used: String, 45 | pub contract_address: String, 46 | pub logs: Vec, 47 | pub return_value: String, 48 | } 49 | -------------------------------------------------------------------------------- /common/src/common/constants.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package common 19 | 20 | // Lengths are in bytes 21 | const ( 22 | PRIVLEN = 32 23 | PUBLEN = 33 24 | STATEADDRLEN = 35 25 | EVMADDRLEN = 20 26 | PREFIXLEN = 3 27 | PREFIX = "a68b06" 28 | GAS_LIMIT = 1 << 31 29 | FAMILY_NAME = "seth" 30 | FAMILY_VERSION = "1.0" 31 | ENCODING = "application/protobuf" 32 | BLOCK_INFO_PREFIX = "00b10c" 33 | BLOCK_INFO_NAMESPACE = BLOCK_INFO_PREFIX + "00" 34 | CONFIG_ADDRESS = BLOCK_INFO_PREFIX + "0100000000000000000000000000000000000000000000000000000000000000" 35 | ) 36 | 37 | func GlobalPermissionsAddress() *EvmAddr { 38 | addr, _ := NewEvmAddrFromBytes([]byte{ 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | }) 42 | return addr 43 | } 44 | -------------------------------------------------------------------------------- /common/src/common/evm_address.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package common 19 | 20 | import ( 21 | "encoding/hex" 22 | "fmt" 23 | ellcurv "github.com/btcsuite/btcd/btcec" 24 | "github.com/hyperledger/burrow/binary" 25 | "github.com/hyperledger/burrow/execution/evm/sha3" 26 | ) 27 | 28 | type EvmAddr [EVMADDRLEN]byte 29 | 30 | func PrivToEvmAddr(priv []byte) (*EvmAddr, error) { 31 | if len(priv) != PRIVLEN { 32 | return nil, fmt.Errorf( 33 | "Incorrect private key length (%v), should be %v", 34 | len(priv), PRIVLEN, 35 | ) 36 | } 37 | _, pub := ellcurv.PrivKeyFromBytes(ellcurv.S256(), priv) 38 | return PubToEvmAddr(pub.SerializeCompressed()) 39 | } 40 | 41 | func PubToEvmAddr(pub []byte) (*EvmAddr, error) { 42 | if len(pub) != PUBLEN { 43 | return nil, fmt.Errorf( 44 | "Incorrect public key length (%v), should be %v", 45 | len(pub), PUBLEN, 46 | ) 47 | } 48 | 49 | return NewEvmAddrFromBytes(sha3.Sha3(pub)[:20]) 50 | } 51 | 52 | func NewEvmAddrFromBytes(b []byte) (*EvmAddr, error) { 53 | var ea EvmAddr 54 | 55 | switch len(b) { 56 | case EVMADDRLEN: 57 | copy(ea[:], b[:EVMADDRLEN]) 58 | return &ea, nil 59 | case STATEADDRLEN: 60 | copy(ea[:], b[PREFIXLEN:PREFIXLEN+EVMADDRLEN]) 61 | return &ea, nil 62 | } 63 | 64 | return nil, fmt.Errorf( 65 | "Malformed address (%v): Length must be %v or %v bytes, not %v", 66 | b, len(b), EVMADDRLEN, STATEADDRLEN, 67 | ) 68 | } 69 | 70 | func NewEvmAddrFromString(s string) (ea *EvmAddr, err error) { 71 | bytes, err := hex.DecodeString(s) 72 | if err != nil { 73 | return nil, fmt.Errorf( 74 | "Malformed address (%s): Invalid hex encoding", s, 75 | ) 76 | } 77 | return NewEvmAddrFromBytes(bytes) 78 | } 79 | 80 | func (ea *EvmAddr) Derive(nonce uint64) *EvmAddr { 81 | if nonce == 0 { 82 | addr, err := NewEvmAddrFromBytes(ea.Bytes()) 83 | if err != nil { 84 | panic(err.Error()) 85 | } 86 | return addr 87 | } 88 | const BUFLEN = EVMADDRLEN + 8 89 | buf := make([]byte, BUFLEN) 90 | copy(buf, ea.Bytes()) 91 | binary.PutUint64BE(buf[EVMADDRLEN:], nonce) 92 | 93 | derived, err := NewEvmAddrFromBytes(sha3.Sha3(buf)[:EVMADDRLEN]) 94 | if err != nil { 95 | panic(err.Error()) 96 | } 97 | return derived 98 | } 99 | 100 | func (ea *EvmAddr) ToWord256() binary.Word256 { 101 | return binary.LeftPadWord256(ea.Bytes()) 102 | } 103 | 104 | func (ea *EvmAddr) String() string { 105 | return hex.EncodeToString(ea.Bytes()) 106 | } 107 | 108 | func (ea *EvmAddr) Bytes() []byte { 109 | return (*ea)[:] 110 | } 111 | 112 | func (ea *EvmAddr) ToStateAddr() StateAddr { 113 | sa, err := NewStateAddrFromBytes(ea.Bytes()) 114 | if err != nil { 115 | panic(err.Error()) 116 | } 117 | return sa 118 | } 119 | -------------------------------------------------------------------------------- /common/src/common/state_address.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package common 19 | 20 | import ( 21 | "encoding/hex" 22 | "fmt" 23 | "github.com/hyperledger/burrow/binary" 24 | ) 25 | 26 | type StateAddr string 27 | 28 | func NewStateAddrFromBytes(b []byte) (StateAddr, error) { 29 | switch len(b) { 30 | case EVMADDRLEN: 31 | b := binary.RightPadBytes(b, 32) 32 | return StateAddr(PREFIX + hex.EncodeToString(b)), nil 33 | case STATEADDRLEN: 34 | return StateAddr(hex.EncodeToString(b)), nil 35 | } 36 | 37 | return "", fmt.Errorf( 38 | "Malformed address (%v): Length must be %v or %v bytes, not %v", 39 | b, len(b), EVMADDRLEN, STATEADDRLEN, 40 | ) 41 | } 42 | 43 | func NewStateAddrFromString(s string) (sa StateAddr, err error) { 44 | bytes, err := hex.DecodeString(s) 45 | if err != nil { 46 | return "", fmt.Errorf( 47 | "Malformed address (%s): Invalid hex encoding", s, 48 | ) 49 | } 50 | return NewStateAddrFromBytes(bytes) 51 | } 52 | 53 | func NewBlockInfoAddr(n int64) (StateAddr, error) { 54 | buf := [8]byte{} 55 | binary.PutInt64BE(buf[:], n) 56 | bytes := binary.LeftPadBytes(buf[:], 31) 57 | return StateAddr(BLOCK_INFO_NAMESPACE + hex.EncodeToString(bytes)), nil 58 | } 59 | 60 | func (sa StateAddr) String() string { 61 | return string(sa) 62 | } 63 | 64 | func (sa StateAddr) ToEvmAddr() *EvmAddr { 65 | ea, err := NewEvmAddrFromString(sa.String()) 66 | if err != nil { 67 | panic(err.Error()) 68 | } 69 | return ea 70 | } 71 | -------------------------------------------------------------------------------- /contracts/examples/contract_chaining/hello_world.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract HelloWorld { 4 | function helloWorld() public pure returns(bytes32) { return "helloworld"; } 5 | } 6 | -------------------------------------------------------------------------------- /contracts/examples/contract_chaining/hello_world.txt: -------------------------------------------------------------------------------- 1 | initialization: 6080604052348015600f57600080fd5b5060a68061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c605f76c14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b60007f68656c6c6f776f726c640000000000000000000000000000000000000000000090509056fea265627a7a7231582055ff626f530f1e47edad47198d4c22f4decaea08d418cd11a5dced135af2c06464736f6c634300050c0032 2 | -------------------------------------------------------------------------------- /contracts/examples/contract_chaining/hello_world_caller.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract HelloWorld { 4 | function helloWorld() public pure returns(bytes32); 5 | } 6 | contract HelloWorldCaller { 7 | function callHelloWorld(address helloWorldAddr) public pure returns(bytes32) { 8 | HelloWorld hello = HelloWorld(helloWorldAddr); 9 | return hello.helloWorld(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/examples/contract_chaining/hello_world_caller.txt: -------------------------------------------------------------------------------- 1 | initialization: 608060405234801561001057600080fd5b5061014c806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b41d7af414610030575b600080fd5b6100726004803603602081101561004657600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610088565b6040518082815260200191505060405180910390f35b6000808290508073ffffffffffffffffffffffffffffffffffffffff1663c605f76c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100d457600080fd5b505afa1580156100e8573d6000803e3d6000fd5b505050506040513d60208110156100fe57600080fd5b810190808051906020019092919050505091505091905056fea265627a7a72315820325769e3d5d735f50dd484e818d153d29465b1cabc6591a3671ada5f36db67ae64736f6c634300050c0032 2 | 3 | callHelloWorld("0xb257af145523371812eb8dfd1b22ddcb18e6a91a"): b41d7af4000000000000000000000000b257af145523371812eb8dfd1b22ddcb18e6a91a 4 | -------------------------------------------------------------------------------- /contracts/examples/opcodes/BlockHash.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract BlockHash { 4 | function blockHash(uint64 blockNum) public view returns (bytes32) { 5 | return blockhash(blockNum); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /contracts/examples/opcodes/BlockHash.txt: -------------------------------------------------------------------------------- 1 | initialization: 2 | 608060405234801561001057600080fd5b5060c08061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c57ffb2d14602d575b600080fd5b606060048036036020811015604157600080fd5b81019080803567ffffffffffffffff1690602001909291905050506076565b6040518082815260200191505060405180910390f35b60008167ffffffffffffffff1640905091905056fea265627a7a72315820d19b318d735d57317b1e17dd3a3e4eaa1e39a3af0883f40484835176f4f1580f64736f6c634300050c0032 3 | 4 | blockHash(1): c57ffb2d0000000000000000000000000000000000000000000000000000000000000001 5 | -------------------------------------------------------------------------------- /contracts/examples/opcodes/BlockNumber.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract BlockNumber { 4 | function blockNumber(uint number) public view returns (uint) { 5 | return block.number - number; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /contracts/examples/opcodes/BlockNumber.txt: -------------------------------------------------------------------------------- 1 | initialization: 6080604052348015600f57600080fd5b5060ad8061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80635030696214602d575b600080fd5b605660048036036020811015604157600080fd5b8101908080359060200190929190505050606c565b6040518082815260200191505060405180910390f35b6000814303905091905056fea265627a7a72315820ca27976be4b77c3ad0cd73511fd6a134977a50c4d80a6d99a39e9c625b1be51d64736f6c634300050c0032 2 | 3 | blocknum(0): 503069620000000000000000000000000000000000000000000000000000000000000000 4 | -------------------------------------------------------------------------------- /contracts/examples/opcodes/Timestamp.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Timestamp { 4 | function timestamp(bool test) public view returns (uint) { 5 | if (test) { 6 | return block.timestamp; 7 | } else { 8 | return 0; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/examples/opcodes/Timestamp.txt: -------------------------------------------------------------------------------- 1 | initialization: 608060405234801561001057600080fd5b5060bb8061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063ffcfdd7614602d575b600080fd5b605860048036036020811015604157600080fd5b81019080803515159060200190929190505050606e565b6040518082815260200191505060405180910390f35b60008115607c574290506081565b600090505b91905056fea265627a7a72315820701b4f1a7a23e2f991e3569f7dc1b35a2bfbdb66d301070e7bc15b17de595ced64736f6c634300050c0032 2 | 3 | timestamp(true): ffcfdd760000000000000000000000000000000000000000000000000000000000000001 4 | -------------------------------------------------------------------------------- /contracts/examples/simple_intkey/simple_intkey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract intkey { 4 | mapping (uint => uint) intmap; 5 | 6 | event Set(uint key, uint value); 7 | 8 | function set(uint key, uint value) public { 9 | intmap[key] = value; 10 | emit Set(key, value); 11 | } 12 | 13 | function inc(uint key) public { 14 | intmap[key] = intmap[key] + 1; 15 | } 16 | 17 | function dec(uint key) public { 18 | intmap[key] = intmap[key] - 1; 19 | } 20 | 21 | function get(uint key) public view returns (uint retVal) { 22 | return intmap[key]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/examples/simple_intkey/simple_intkey.txt: -------------------------------------------------------------------------------- 1 | initialization: 608060405234801561001057600080fd5b50610230806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80631ab06ee514610051578063812600df146100895780639507d39a146100b7578063c20efb90146100f9575b600080fd5b6100876004803603604081101561006757600080fd5b810190808035906020019092919080359060200190929190505050610127565b005b6100b56004803603602081101561009f57600080fd5b8101908080359060200190929190505050610181565b005b6100e3600480360360208110156100cd57600080fd5b81019080803590602001909291905050506101b0565b6040518082815260200191505060405180910390f35b6101256004803603602081101561010f57600080fd5b81019080803590602001909291905050506101cc565b005b80600080848152602001908152602001600020819055507f545b620a3000f6303b158b321f06b4e95e28a27d70aecac8c6bdac4f48a9f6b38282604051808381526020018281526020019250505060405180910390a15050565b600160008083815260200190815260200160002054016000808381526020019081526020016000208190555050565b6000806000838152602001908152602001600020549050919050565b60016000808381526020019081526020016000205403600080838152602001908152602001600020819055505056fea265627a7a723158205882aeb135ba160e223cba71c20338844bfd394bb4e5509c67c86bd09910689564736f6c634300050c0032 2 | 3 | set(0, 42) 4 | 1ab06ee50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a 5 | 6 | set(19, 84) 7 | 1ab06ee500000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000000000000000000000000000000000000054 8 | 9 | get(0) 10 | 9507d39a0000000000000000000000000000000000000000000000000000000000000000 11 | 12 | get(19) 13 | 9507d39a0000000000000000000000000000000000000000000000000000000000000013 14 | 15 | inc(19) 16 | 812600df0000000000000000000000000000000000000000000000000000000000000013 17 | 18 | inc(0) 19 | 812600df0000000000000000000000000000000000000000000000000000000000000000 20 | 21 | dec(19) 22 | c20efb900000000000000000000000000000000000000000000000000000000000000013 23 | 24 | dec(0) 25 | c20efb900000000000000000000000000000000000000000000000000000000000000000 26 | -------------------------------------------------------------------------------- /docker/compose/copy-debs.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Cargill Incorporated 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | version: '3.6' 16 | 17 | services: 18 | 19 | sawtooth-seth-cli: 20 | image: sawtooth-seth-cli:${ISOLATION_ID} 21 | volumes: 22 | - ../../build/debs:/build/debs 23 | command: | 24 | bash -c " 25 | cp /debs/*.deb /build/debs 26 | " 27 | 28 | sawtooth-seth-tp: 29 | image: sawtooth-seth-tp:${ISOLATION_ID} 30 | volumes: 31 | - ../../build/debs:/build/debs 32 | command: | 33 | bash -c " 34 | cp /debs/*.deb /build/debs 35 | " 36 | 37 | sawtooth-seth-rpc: 38 | image: sawtooth-seth-rpc:${ISOLATION_ID} 39 | volumes: 40 | - ../../build/debs:/build/debs 41 | command: | 42 | bash -c " 43 | cp /debs/*.deb /build/debs 44 | " 45 | -------------------------------------------------------------------------------- /docs/source/_templates/indexcontent.html: -------------------------------------------------------------------------------- 1 | {%- extends "layout.html" %} 2 | {% set title = 'Overview' %} 3 | {% block body %} 4 | 5 |

Hyperledger Sawtooth Seth documentation

6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | {% endblock %} 17 | -------------------------------------------------------------------------------- /docs/source/cli_reference.rst: -------------------------------------------------------------------------------- 1 | .. 2 | Copyright 2017 Intel Corporation 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | ************* 17 | CLI Reference 18 | ************* 19 | 20 | .. _seth-cli-reference-label: 21 | 22 | Seth Client Usage 23 | ================= 24 | 25 | seth 26 | ---- 27 | 28 | .. literalinclude:: /cli/output/seth_usage.out 29 | :language: console 30 | :linenos: 31 | 32 | seth init 33 | --------- 34 | .. literalinclude:: /cli/output/seth_init_usage.out 35 | :language: console 36 | :linenos: 37 | 38 | seth show 39 | --------- 40 | .. literalinclude:: /cli/output/seth_show_usage.out 41 | :language: console 42 | :linenos: 43 | 44 | seth account 45 | ------------ 46 | .. literalinclude:: /cli/output/seth_account_usage.out 47 | :language: console 48 | :linenos: 49 | 50 | seth account import 51 | ------------------- 52 | .. literalinclude:: /cli/output/seth_account_import_usage.out 53 | :language: console 54 | :linenos: 55 | 56 | seth account list 57 | ----------------- 58 | .. literalinclude:: /cli/output/seth_account_list_usage.out 59 | :language: console 60 | :linenos: 61 | 62 | seth account create 63 | ------------------- 64 | .. literalinclude:: /cli/output/seth_account_create_usage.out 65 | :language: console 66 | :linenos: 67 | 68 | seth contract 69 | ------------- 70 | .. literalinclude:: /cli/output/seth_contract_usage.out 71 | :language: console 72 | :linenos: 73 | 74 | seth contract call 75 | ------------------ 76 | .. literalinclude:: /cli/output/seth_contract_call_usage.out 77 | :language: console 78 | :linenos: 79 | 80 | seth contract create 81 | -------------------- 82 | .. literalinclude:: /cli/output/seth_contract_create_usage.out 83 | :language: console 84 | :linenos: 85 | 86 | seth permissions 87 | ---------------- 88 | .. literalinclude:: /cli/output/seth_permissions_usage.out 89 | :language: console 90 | :linenos: 91 | 92 | seth permissions set 93 | -------------------- 94 | .. literalinclude:: /cli/output/seth_permissions_set_usage.out 95 | :language: console 96 | :linenos: 97 | 98 | .. _seth-tp-reference-label: 99 | 100 | Seth Transaction Processor Usage 101 | ================================ 102 | 103 | seth-tp 104 | ------- 105 | 106 | .. literalinclude:: /cli/output/seth-tp_usage.out 107 | :language: console 108 | :linenos: 109 | 110 | .. _seth-rpc-reference-label: 111 | 112 | Seth RPC Usage 113 | ============== 114 | 115 | seth-rpc 116 | -------- 117 | 118 | .. literalinclude:: /cli/output/seth-rpc_usage.out 119 | :language: console 120 | :linenos: 121 | -------------------------------------------------------------------------------- /docs/source/community.rst: -------------------------------------------------------------------------------- 1 | ********* 2 | Community 3 | ********* 4 | 5 | Welcome to the Sawtooth community! 6 | 7 | For help topics, we recommend joining us on Chat (link below). 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | community/join_the_discussion 13 | community/issue_tracking 14 | community/contributing 15 | community/code_of_conduct 16 | 17 | -------------------------------------------------------------------------------- /docs/source/community/code_of_conduct.rst: -------------------------------------------------------------------------------- 1 | Code of Conduct 2 | =============== 3 | 4 | When participating, please be respectful and courteous. 5 | 6 | Sawtooth Seth uses the `Hyperledger Project Code of Conduct 7 | `_. 8 | -------------------------------------------------------------------------------- /docs/source/community/contributing.rst: -------------------------------------------------------------------------------- 1 | ------------ 2 | Contributing 3 | ------------ 4 | 5 | ================== 6 | Ways to Contribute 7 | ================== 8 | 9 | Contributions by the community help grow and optimize the capabilities of 10 | Sawtooth Seth, and are the most effective method of having a positive 11 | impact on the project. 12 | 13 | **Different ways you can contribute** 14 | 15 | * Bugs or Issues (issues or defects found when working with Sawtooth Seth) 16 | * Core Features & Enhancements (expanded capabilities or optimization) 17 | * New or Enhanced Documentation (improve existing documentation or create new) 18 | * Testing Events and Results (functional, performance, or scalability) 19 | 20 | **Unassigned JIRA Issues** 21 | 22 | More specific items can be found in :ref:`jira`. Any JIRA items which are 23 | unassigned are probably still open. If in doubt, ask on :ref:`chat` about 24 | the particular JIRA issue. 25 | 26 | ============== 27 | Commit Process 28 | ============== 29 | 30 | Hyperledger Sawtooth is Apache 2.0 licensed and accepts contributions 31 | via `GitHub `_ 32 | pull requests. When contributing code please do the following: 33 | 34 | * Fork the repository and make your changes in a feature branch. 35 | * Please include unit and integration tests for any new features and updates 36 | to existing tests. 37 | * Please ensure the unit and integration tests run successfully. Both are run 38 | with `./bin/run_tests`. 39 | 40 | **Pull Request Guidelines** 41 | 42 | Pull requests can contain a single commit or multiple commits. The most 43 | important part is that **a single commit maps to a single fix or enhancement**. 44 | 45 | Here are a few scenarios: 46 | 47 | * If a pull request adds a feature but also fixes two bugs, then the pull 48 | request should have three commits, one commit each for the feature and two 49 | bug fixes 50 | * If a PR is opened with 5 commits that was work involved to fix a single issue, 51 | it should be rebased to a single commit 52 | * If a PR is opened with 5 commits, with the first three to fix one issue and 53 | the second two to fix a separate issue, then it should be rebased to two 54 | commits, one for each issue 55 | 56 | Your pull request should be rebased against the current master branch. Please do 57 | not merge the current master branch in with your topic branch, nor use the 58 | Update Branch button provided by GitHub on the pull request page. 59 | 60 | **Commit Messages** 61 | 62 | Commit messages should follow common Git conventions, such as the imperative 63 | mood, separate subject lines, and a line-length of 72 characters. These rules 64 | are well documented by Chris Beam in 65 | `his blog post `_ on the 66 | subject. 67 | 68 | **Signed-off-by** 69 | 70 | Commits must include Signed-off-by in the commit message (``git commit -s``). 71 | This indicates that you agree the commit satisfies the 72 | `Developer Certificate of Origin (DCO) `_. 73 | 74 | **Important GitHub Requirements** 75 | 76 | PLEASE NOTE: Pull requests can only be merged after they have passed all 77 | status checks. 78 | 79 | These checks are: 80 | 81 | * The build must pass on Jenkins 82 | * The PR must be approved by at least two reviewers and there cannot be 83 | outstanding changes requested 84 | 85 | **Integrating GitHub Commits with JIRA** 86 | 87 | You can link JIRA issues to your Sawtooth Seth GitHub commits to integrate 88 | development activity with the associated issue. JIRA uses the issue key to 89 | associate the commit with the issue, so the commit can be summarized in the 90 | development panel for the JIRA issue. 91 | 92 | When you make a commit, add the JIRA issue key to the end of the commit message. 93 | Alternatively, you can add the JIRA issue key to the branch name. Either method 94 | should integrate your commit with the JIRA issue it references. 95 | -------------------------------------------------------------------------------- /docs/source/community/issue_tracking.rst: -------------------------------------------------------------------------------- 1 | ************** 2 | Issue Tracking 3 | ************** 4 | 5 | .. _jira: 6 | 7 | Reporting Issues 8 | ================ 9 | 10 | This is a great way to contribute. Before reporting an issue, please review current 11 | open issues to see if there are any matches. 12 | 13 | How to Report an Issue 14 | ====================== 15 | 16 | Issues should be created in JIRA under the Hyperledger Sawtooth project (which 17 | uses the *STL* JIRA key), and have the *Seth* component added to them. 18 | 19 | When reporting an issue, please provide as much detail as possible about how 20 | to reproduce it. If possible, provide instructions for how to reproduce the 21 | issue within the vagrant development environment. 22 | 23 | Details are key. Please include the following: 24 | 25 | * OS version 26 | * Seth version 27 | * Environment details (virtual, physical, etc.) 28 | * Steps to reproduce 29 | * Actual results 30 | * Expected results 31 | 32 | If you would like, you could also bring up the issue on :ref:`chat` for initial 33 | feedback before submitting the issue in JIRA. 34 | 35 | JIRA 36 | ==== 37 | 38 | Sawtooth Seth uses `JIRA as our issue tracking system `_. 40 | 41 | To report issues, you will need to log into Hyperledger Sawtooth JIRA, which requires a 42 | `Linux Foundation Account `_ 43 | 44 | 45 | -------------------------------------------------------------------------------- /docs/source/community/join_the_discussion.rst: -------------------------------------------------------------------------------- 1 | ******************* 2 | Join the Discussion 3 | ******************* 4 | 5 | .. _chat: 6 | 7 | Chat 8 | ==== 9 | 10 | Hyperledger Sawtooth RocketChat is the place to go for real-time chat about 11 | everything from quick help to involved discussion. 12 | 13 | Sawtooth Seth discussions are located at: 14 | 15 | `#sawtooth-seth `_ 16 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Sawtooth documentation build configuration file, created by 4 | # sphinx-quickstart on Wed Dec 2 11:03:19 2015. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | # Add any Sphinx extension module names here, as strings. They can be 16 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 17 | # ones. 18 | extensions = [ 19 | "sphinx.ext.autodoc", 20 | ] 21 | 22 | # Autodoc settings 23 | autodoc_member_order = "bysource" 24 | autoclass_content = "both" 25 | 26 | # Add any paths that contain templates here, relative to this directory. 27 | templates_path = ["_templates"] 28 | 29 | # The suffix(es) of source filenames. 30 | # You can specify multiple suffix as a list of string: 31 | # source_suffix = ['.rst', '.md'] 32 | source_suffix = ".rst" 33 | 34 | # The master toctree document. 35 | master_doc = "contents" 36 | 37 | # General information about the project. 38 | project = "Sawtooth Seth" 39 | copyright = "2015-2018, Intel Corporation" 40 | author = "Hyperledger Sawtooth Contributors" 41 | 42 | # The version info for the project you're documenting, acts as replacement for 43 | # |version| and |release|, also used in various other places throughout the 44 | # built documents. 45 | # 46 | # The short X.Y version. 47 | version = "latest" 48 | # The full version, including alpha/beta/rc tags. 49 | release = "latest" 50 | 51 | # The language for content autogenerated by Sphinx. Refer to documentation 52 | # for a list of supported languages. 53 | # 54 | # This is also used if you do content translation via gettext catalogs. 55 | # Usually you set "language" from the command line for these cases. 56 | language = None 57 | 58 | # List of patterns, relative to source directory, that match files and 59 | # directories to ignore when looking for source files. 60 | exclude_patterns = ["community/how_to_report_issues.rst"] 61 | 62 | # The name of the Pygments (syntax highlighting) style to use. 63 | pygments_style = "sphinx" 64 | 65 | # -- Options for HTML output ---------------------------------------------- 66 | 67 | # The theme to use for HTML and HTML Help pages. See the documentation for 68 | # a list of builtin themes. 69 | html_theme = "sphinx_rtd_theme" 70 | 71 | # Additional templates that should be rendered to pages, maps page names to 72 | # template names. 73 | html_additional_pages = {"index": "indexcontent.html"} 74 | 75 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 76 | html_show_sphinx = False 77 | 78 | # Output file base name for HTML help builder. 79 | htmlhelp_basename = "SawtoothSethDoc" 80 | 81 | PREAMBLE = "" 82 | 83 | # -- Options for LaTeX output --------------------------------------------- 84 | 85 | latex_elements = {"preamble": PREAMBLE} 86 | 87 | # Grouping the document tree into LaTeX files. List of tuples 88 | # (source start file, target name, title, 89 | # author, documentclass [howto, manual, or own class]). 90 | latex_documents = [ 91 | (master_doc, "sawtooth-seth.tex", "Sawtooth Seth Documentation", author, "manual") 92 | ] 93 | 94 | 95 | # -- Options for Texinfo output ------------------------------------------- 96 | 97 | # Grouping the document tree into Texinfo files. List of tuples 98 | # (source start file, target name, title, author, 99 | # dir menu entry, description, category) 100 | texinfo_documents = [ 101 | ( 102 | master_doc, 103 | "SawtoothSeth", 104 | "Sawtooth Seth Documentation", 105 | author, 106 | "SawtoothSeth", 107 | "Ethereum-compatible transaction family for the Hyperledger Sawtooth platform", 108 | "Miscellaneous", 109 | ) 110 | ] 111 | -------------------------------------------------------------------------------- /docs/source/contents.rst: -------------------------------------------------------------------------------- 1 | ********************* 2 | Seth Developers Guide 3 | ********************* 4 | 5 | .. 6 | introduction 7 | - What is Seth? 8 | - Collaboration with Burrow 9 | - Why did we create it? 10 | - What it is not. 11 | getting_started 12 | - Getting Seth 13 | - Setting up a development environment 14 | - Generating keys and creating a new external account 15 | contracts 16 | - Creating a contract, Solidity 17 | - Compiling the contract: {solc} 18 | - Deploying the contract: {seth} 19 | - Calling the contract: ABI and {seth} 20 | permissions 21 | - The permission flags 22 | - Global permissions 23 | - Changing permissions 24 | developing dapps 25 | - Setting up seth-rpc 26 | - Querying network state 27 | - Deploying contracts 28 | - Calling contracts 29 | - Getting logs 30 | - Using web3.js 31 | seth_transaction_family_spec 32 | - transactions 33 | - payloads 34 | - receipts 35 | - events 36 | cli reference 37 | - seth 38 | - seth_tp 39 | - seth_rpc 40 | 41 | .. toctree:: 42 | :maxdepth: 2 43 | 44 | introduction 45 | getting_started 46 | contracts 47 | permissions 48 | dapps 49 | seth_transaction_family_spec 50 | cli_reference 51 | community -------------------------------------------------------------------------------- /docs/source/images/seth_JSON_RPC.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyperledger-archives/sawtooth-seth/7c6d86ec8aa560a84f60cd1ad10995eac6616c06/docs/source/images/seth_JSON_RPC.pdf -------------------------------------------------------------------------------- /docs/source/introduction.rst: -------------------------------------------------------------------------------- 1 | .. 2 | Copyright 2017 Intel Corporation 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | ************ 17 | Introduction 18 | ************ 19 | 20 | The primary goal of the Sawtooth-Ethereum integration project, affectionately 21 | dubbed "Seth", is to add support for running Ethereum Virtual Machine smart 22 | contracts to the Hyperledger Sawtooth platform. In order to make this possible, 23 | the Hyperledger Sawtooth project worked with the `Hyperledger Burrow`_ project 24 | to integrate their EVM implementation, the Burrow EVM, into with the Hyperledger 25 | Sawtooth platform. 26 | 27 | .. _Hyperledger Burrow: https://github.com/hyperledger/burrow 28 | 29 | The secondary goal of Seth is to make it easy to port existing EVM smart 30 | contracts and DApps that depend on them to Sawtooth. This has been largely 31 | accomplished by replicating the `Ethereum JSON RPC API`_. 32 | 33 | .. _Ethereum JSON RPC API: https://github.com/ethereum/wiki/wiki/JSON-RPC 34 | 35 | Seth is composed of three components: 36 | 37 | 1. The :ref:`seth ` client 38 | #. The :ref:`seth-tp ` transaction processor 39 | #. The :ref:`seth-rpc ` server 40 | 41 | The ``seth`` client is the user-facing CLI tool for interacting with a Sawtooth 42 | network that has Seth deployed on it. The ``seth-tp`` transaction processor is 43 | the component that implements "Ethereum-like" functionality within the Sawtooth 44 | platform. Running Seth on a Sawtooth network is equivalent to connecting a 45 | ``seth-tp`` process to all validator nodes. The ``seth-rpc`` server is an HTTP 46 | server that acts as an adapter between the `Ethereum JSON RPC API`_ and the 47 | client interface provided by Sawtooth. 48 | 49 | It is important to note that Seth is not a complete Ethereum implementation. The 50 | Sawtooth platform has made fundamental design decisions that differ from those 51 | made by the Ethereum platform. While most EVM smart contracts can be run on the 52 | Sawtooth network, there are some differences to be aware of: 53 | 54 | 1. Blocks within Sawtooth are not identified by a 32-byte block hash. They are 55 | instead identified by a 64-byte header signature. When running smart 56 | contracts that use the BLOCKHASH instruction, the first 32 bytes of the 57 | header signature are used in place of a block hash. 58 | #. The public Ethereum network depends on economic incentives to limit execution 59 | resources. On the other hand, the Hyperledger Burrow project depends on 60 | permissions to control and limit execution resources. Seth currently only 61 | supports the permissioned-network model. As a consequence, "gas" is free but 62 | finite and permissions can be applied to all accounts. 63 | #. Transaction execution within Sawtooth is modularized so that transactions 64 | cannot have knowledge of being executed within the context of a block chain. 65 | This feature has useful implications from a design perspective, such as 66 | simplifying the Sawtooth state transaction function. However, it is in 67 | direct opposition to transaction execution within Ethereum, in which 68 | transactions can depend on the block numbers, hashes, and timestamps. By 69 | default, these instructions are not supported by Seth. However, if the Block 70 | Info Transaction Family is running on the same network as Seth, these 71 | instructions will attempt to read from state at the addresses defined by that 72 | family. 73 | 74 | .. note:: 75 | 76 | Code documentation can be `found here <../cargo/seth/index.html>`_. -------------------------------------------------------------------------------- /integration/sawtooth_integration/docker/seth_blockhash_test.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: '2.1' 17 | 18 | services: 19 | seth-tp: 20 | build: 21 | context: ../../.. 22 | dockerfile: ./processor/Dockerfile 23 | args: 24 | ISOLATION_ID: ${ISOLATION_ID} 25 | image: sawtooth-seth-tp:${ISOLATION_ID} 26 | depends_on: 27 | - validator 28 | command: | 29 | bash -c " 30 | seth-tp -vv \ 31 | -C tcp://validator:4004 32 | " 33 | 34 | block-info-tp: 35 | image: hyperledger/sawtooth-block-info-tp:1.0 36 | depends_on: 37 | - validator 38 | command: block-info-tp -vv --connect tcp://validator:4004 39 | 40 | settings-tp: 41 | image: hyperledger/sawtooth-settings-tp:1.0 42 | depends_on: 43 | - validator 44 | command: settings-tp -vv --connect tcp://validator:4004 45 | 46 | rest-api: 47 | image: hyperledger/sawtooth-rest-api:1.0 48 | expose: 49 | - 4004 50 | - 8080 51 | depends_on: 52 | - validator 53 | entrypoint: | 54 | sawtooth-rest-api -vv 55 | --connect tcp://validator:4004 56 | --bind rest-api:8080 57 | 58 | validator: 59 | image: hyperledger/sawtooth-validator:1.0 60 | ports: 61 | - 4004 62 | - 8800 63 | command: | 64 | bash -c " 65 | if [ ! -f /etc/keys/validator.priv ]; then 66 | sawadm keygen && 67 | sawset genesis \ 68 | -k /etc/sawtooth/keys/validator.priv \ 69 | -o config-genesis.batch && 70 | sawset proposal create \ 71 | -k /etc/sawtooth/keys/validator.priv \ 72 | sawtooth.validator.batch_injectors=block_info \ 73 | -o config.batch && 74 | sawadm genesis config-genesis.batch config.batch 75 | fi; 76 | sawtooth-validator -vv \ 77 | --endpoint tcp://validator:8800 \ 78 | --bind component:tcp://eth0:4004 \ 79 | --bind network:tcp://eth0:8800 80 | " 81 | 82 | seth-blockhash-test: 83 | build: 84 | context: ../../.. 85 | dockerfile: ./cli/Dockerfile 86 | args: 87 | ISOLATION_ID: ${ISOLATION_ID} 88 | image: sawtooth-seth-cli-go:${ISOLATION_ID} 89 | expose: 90 | - 8080 91 | depends_on: 92 | - validator 93 | - rest-api 94 | working_dir: /project/sawtooth-seth/integration/sawtooth_integration/tests 95 | command: test-entrypoint go test seth_blockhash_test.go 96 | stop_signal: SIGKILL 97 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/docker/seth_blocknum_test.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: '2.1' 17 | 18 | services: 19 | seth-tp: 20 | build: 21 | context: ../../.. 22 | dockerfile: ./processor/Dockerfile 23 | args: 24 | ISOLATION_ID: ${ISOLATION_ID} 25 | image: sawtooth-seth-tp:${ISOLATION_ID} 26 | depends_on: 27 | - validator 28 | command: | 29 | bash -c " 30 | seth-tp -vv \ 31 | -C tcp://validator:4004 32 | " 33 | 34 | block-info-tp: 35 | image: hyperledger/sawtooth-block-info-tp:1.0 36 | depends_on: 37 | - validator 38 | command: block-info-tp -vv --connect tcp://validator:4004 39 | 40 | settings-tp: 41 | image: hyperledger/sawtooth-settings-tp:1.0 42 | depends_on: 43 | - validator 44 | command: settings-tp -vv --connect tcp://validator:4004 45 | 46 | rest-api: 47 | image: hyperledger/sawtooth-rest-api:1.0 48 | expose: 49 | - 4004 50 | - 8080 51 | depends_on: 52 | - validator 53 | entrypoint: | 54 | sawtooth-rest-api -vv 55 | --connect tcp://validator:4004 56 | --bind rest-api:8080 57 | 58 | validator: 59 | image: hyperledger/sawtooth-validator:1.0 60 | ports: 61 | - 4004 62 | - 8800 63 | command: | 64 | bash -c " 65 | if [ ! -f /etc/keys/validator.priv ]; then 66 | sawadm keygen && 67 | sawset genesis \ 68 | -k /etc/sawtooth/keys/validator.priv \ 69 | -o config-genesis.batch && 70 | sawset proposal create \ 71 | -k /etc/sawtooth/keys/validator.priv \ 72 | sawtooth.validator.batch_injectors=block_info \ 73 | -o config.batch && 74 | sawadm genesis config-genesis.batch config.batch 75 | fi; 76 | sawtooth-validator -vv \ 77 | --endpoint tcp://validator:8800 \ 78 | --bind component:tcp://eth0:4004 \ 79 | --bind network:tcp://eth0:8800 80 | " 81 | 82 | seth-blocknum-test: 83 | build: 84 | context: ../../.. 85 | dockerfile: ./cli/Dockerfile 86 | args: 87 | ISOLATION_ID: ${ISOLATION_ID} 88 | image: sawtooth-seth-cli-go:${ISOLATION_ID} 89 | expose: 90 | - 8080 91 | depends_on: 92 | - validator 93 | - rest-api 94 | working_dir: /project/sawtooth-seth/integration/sawtooth_integration/tests 95 | command: test-entrypoint go test seth_blocknum_test.go 96 | stop_signal: SIGKILL 97 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/docker/seth_chaining_test.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: '2.1' 17 | 18 | services: 19 | seth-tp: 20 | build: 21 | context: ../../.. 22 | dockerfile: ./processor/Dockerfile 23 | args: 24 | ISOLATION_ID: ${ISOLATION_ID} 25 | image: sawtooth-seth-tp:${ISOLATION_ID} 26 | depends_on: 27 | - validator 28 | command: | 29 | bash -c " 30 | seth-tp -vv \ 31 | -C tcp://validator:4004 32 | " 33 | 34 | block-info-tp: 35 | image: hyperledger/sawtooth-block-info-tp:1.0 36 | depends_on: 37 | - validator 38 | command: block-info-tp -vv --connect tcp://validator:4004 39 | 40 | settings-tp: 41 | image: hyperledger/sawtooth-settings-tp:1.0 42 | depends_on: 43 | - validator 44 | command: settings-tp -vv --connect tcp://validator:4004 45 | 46 | rest-api: 47 | image: hyperledger/sawtooth-rest-api:1.0 48 | expose: 49 | - 4004 50 | - 8080 51 | depends_on: 52 | - validator 53 | entrypoint: | 54 | sawtooth-rest-api -vv 55 | --connect tcp://validator:4004 56 | --bind rest-api:8080 57 | 58 | validator: 59 | image: hyperledger/sawtooth-validator:1.0 60 | ports: 61 | - 4004 62 | - 8800 63 | command: | 64 | bash -c " 65 | if [ ! -f /etc/keys/validator.priv ]; then 66 | sawadm keygen && 67 | sawset genesis \ 68 | -k /etc/sawtooth/keys/validator.priv \ 69 | -o config-genesis.batch && 70 | sawset proposal create \ 71 | -k /etc/sawtooth/keys/validator.priv \ 72 | sawtooth.validator.batch_injectors=block_info \ 73 | -o config.batch && 74 | sawadm genesis config-genesis.batch config.batch 75 | fi; 76 | sawtooth-validator -vv \ 77 | --endpoint tcp://validator:8800 \ 78 | --bind component:tcp://eth0:4004 \ 79 | --bind network:tcp://eth0:8800 80 | " 81 | 82 | seth-chaining-test: 83 | build: 84 | context: ../../.. 85 | dockerfile: ./cli/Dockerfile 86 | args: 87 | ISOLATION_ID: ${ISOLATION_ID} 88 | image: sawtooth-seth-cli-go:${ISOLATION_ID} 89 | expose: 90 | - 8080 91 | depends_on: 92 | - validator 93 | - rest-api 94 | working_dir: /project/sawtooth-seth/integration/sawtooth_integration/tests 95 | command: test-entrypoint go test seth_chaining_test.go 96 | stop_signal: SIGKILL 97 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/docker/seth_client_test.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: '2.1' 17 | 18 | services: 19 | seth-tp: 20 | build: 21 | context: ../../.. 22 | dockerfile: ./processor/Dockerfile 23 | args: 24 | ISOLATION_ID: ${ISOLATION_ID} 25 | image: sawtooth-seth-tp:${ISOLATION_ID} 26 | depends_on: 27 | - validator 28 | command: | 29 | bash -c " 30 | seth-tp -vv \ 31 | -C tcp://validator:4004 32 | " 33 | 34 | block-info-tp: 35 | image: hyperledger/sawtooth-block-info-tp:1.0 36 | depends_on: 37 | - validator 38 | command: block-info-tp -vv --connect tcp://validator:4004 39 | 40 | settings-tp: 41 | image: hyperledger/sawtooth-settings-tp:1.0 42 | depends_on: 43 | - validator 44 | command: settings-tp -vv --connect tcp://validator:4004 45 | 46 | rest-api: 47 | image: hyperledger/sawtooth-rest-api:1.0 48 | expose: 49 | - 4004 50 | - 8080 51 | depends_on: 52 | - validator 53 | entrypoint: | 54 | sawtooth-rest-api -vv 55 | --connect tcp://validator:4004 56 | --bind rest-api:8080 57 | 58 | validator: 59 | image: hyperledger/sawtooth-validator:1.0 60 | ports: 61 | - 4004 62 | - 8800 63 | command: | 64 | bash -c " 65 | if [ ! -f /etc/keys/validator.priv ]; then 66 | sawadm keygen && 67 | sawset genesis \ 68 | -k /etc/sawtooth/keys/validator.priv \ 69 | -o config-genesis.batch && 70 | sawset proposal create \ 71 | -k /etc/sawtooth/keys/validator.priv \ 72 | sawtooth.validator.batch_injectors=block_info \ 73 | -o config.batch && 74 | sawadm genesis config-genesis.batch config.batch 75 | fi; 76 | sawtooth-validator -vv \ 77 | --endpoint tcp://validator:8800 \ 78 | --bind component:tcp://eth0:4004 \ 79 | --bind network:tcp://eth0:8800 80 | " 81 | 82 | seth-client-test: 83 | build: 84 | context: ../../.. 85 | dockerfile: ./cli/Dockerfile 86 | args: 87 | ISOLATION_ID: ${ISOLATION_ID} 88 | image: sawtooth-seth-cli-go:${ISOLATION_ID} 89 | expose: 90 | - 8080 91 | depends_on: 92 | - validator 93 | - rest-api 94 | working_dir: /project/sawtooth-seth/integration/sawtooth_integration/tests 95 | command: go test seth_client_test.go 96 | stop_signal: SIGKILL 97 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/docker/seth_intkey_test.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: '2.1' 17 | 18 | services: 19 | seth-tp: 20 | build: 21 | context: ../../.. 22 | dockerfile: ./processor/Dockerfile 23 | args: 24 | ISOLATION_ID: ${ISOLATION_ID} 25 | image: sawtooth-seth-tp:${ISOLATION_ID} 26 | depends_on: 27 | - validator 28 | command: | 29 | bash -c " 30 | seth-tp -vv \ 31 | -C tcp://validator:4004 32 | " 33 | 34 | block-info-tp: 35 | image: hyperledger/sawtooth-block-info-tp:1.0 36 | depends_on: 37 | - validator 38 | command: block-info-tp -vv --connect tcp://validator:4004 39 | 40 | settings-tp: 41 | image: hyperledger/sawtooth-settings-tp:1.0 42 | depends_on: 43 | - validator 44 | command: settings-tp -vv --connect tcp://validator:4004 45 | 46 | rest-api: 47 | image: hyperledger/sawtooth-rest-api:1.0 48 | expose: 49 | - 4004 50 | - 8080 51 | depends_on: 52 | - validator 53 | entrypoint: | 54 | sawtooth-rest-api -vv 55 | --connect tcp://validator:4004 56 | --bind rest-api:8080 57 | 58 | validator: 59 | image: hyperledger/sawtooth-validator:1.0 60 | ports: 61 | - 4004 62 | - 8800 63 | command: | 64 | bash -c " 65 | if [ ! -f /etc/keys/validator.priv ]; then 66 | sawadm keygen && 67 | sawset genesis \ 68 | -k /etc/sawtooth/keys/validator.priv \ 69 | -o config-genesis.batch && 70 | sawset proposal create \ 71 | -k /etc/sawtooth/keys/validator.priv \ 72 | sawtooth.validator.batch_injectors=block_info \ 73 | -o config.batch && 74 | sawadm genesis config-genesis.batch config.batch 75 | fi; 76 | sawtooth-validator -vv \ 77 | --endpoint tcp://validator:8800 \ 78 | --bind component:tcp://eth0:4004 \ 79 | --bind network:tcp://eth0:8800 80 | " 81 | 82 | seth-intkey-test: 83 | build: 84 | context: ../../.. 85 | dockerfile: ./cli/Dockerfile 86 | args: 87 | ISOLATION_ID: ${ISOLATION_ID} 88 | image: sawtooth-seth-cli-go:${ISOLATION_ID} 89 | expose: 90 | - 8080 91 | depends_on: 92 | - validator 93 | - rest-api 94 | working_dir: /project/sawtooth-seth/integration/sawtooth_integration/tests 95 | command: test-entrypoint go test seth_intkey_test.go 96 | stop_signal: SIGKILL 97 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/docker/seth_perm_test.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: '2.1' 17 | 18 | services: 19 | seth-tp: 20 | build: 21 | context: ../../.. 22 | dockerfile: ./processor/Dockerfile 23 | args: 24 | ISOLATION_ID: ${ISOLATION_ID} 25 | image: sawtooth-seth-tp:${ISOLATION_ID} 26 | depends_on: 27 | - validator 28 | command: | 29 | bash -c " 30 | seth-tp -vv \ 31 | -C tcp://validator:4004 32 | " 33 | 34 | block-info-tp: 35 | image: hyperledger/sawtooth-block-info-tp:1.0 36 | depends_on: 37 | - validator 38 | command: block-info-tp -vv --connect tcp://validator:4004 39 | 40 | settings-tp: 41 | image: hyperledger/sawtooth-settings-tp:1.0 42 | depends_on: 43 | - validator 44 | command: settings-tp -vv --connect tcp://validator:4004 45 | 46 | rest-api: 47 | image: hyperledger/sawtooth-rest-api:1.0 48 | expose: 49 | - 4004 50 | - 8080 51 | depends_on: 52 | - validator 53 | entrypoint: | 54 | sawtooth-rest-api -vv 55 | --connect tcp://validator:4004 56 | --bind rest-api:8080 57 | 58 | validator: 59 | image: hyperledger/sawtooth-validator:1.0 60 | ports: 61 | - 4004 62 | - 8800 63 | command: | 64 | bash -c " 65 | if [ ! -f /etc/keys/validator.priv ]; then 66 | sawadm keygen && 67 | sawset genesis \ 68 | -k /etc/sawtooth/keys/validator.priv \ 69 | -o config-genesis.batch && 70 | sawset proposal create \ 71 | -k /etc/sawtooth/keys/validator.priv \ 72 | sawtooth.validator.batch_injectors=block_info \ 73 | -o config.batch && 74 | sawadm genesis config-genesis.batch config.batch 75 | fi; 76 | sawtooth-validator -vv \ 77 | --endpoint tcp://validator:8800 \ 78 | --bind component:tcp://eth0:4004 \ 79 | --bind network:tcp://eth0:8800 80 | " 81 | 82 | seth-perm-test: 83 | build: 84 | context: ../../.. 85 | dockerfile: ./cli/Dockerfile 86 | args: 87 | ISOLATION_ID: ${ISOLATION_ID} 88 | image: sawtooth-seth-cli-go:${ISOLATION_ID} 89 | expose: 90 | - 8080 91 | depends_on: 92 | - validator 93 | - rest-api 94 | working_dir: /project/sawtooth-seth/integration/sawtooth_integration/tests 95 | command: test-entrypoint go test seth_perm_test.go 96 | stop_signal: SIGKILL 97 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/docker/seth_timestamp_test.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: '2.1' 17 | 18 | services: 19 | seth-tp: 20 | build: 21 | context: ../../.. 22 | dockerfile: ./processor/Dockerfile 23 | args: 24 | ISOLATION_ID: ${ISOLATION_ID} 25 | image: sawtooth-seth-tp:${ISOLATION_ID} 26 | depends_on: 27 | - validator 28 | command: | 29 | bash -c " 30 | seth-tp -vv \ 31 | -C tcp://validator:4004 32 | " 33 | 34 | block-info-tp: 35 | image: hyperledger/sawtooth-block-info-tp:1.0 36 | depends_on: 37 | - validator 38 | command: block-info-tp -vv --connect tcp://validator:4004 39 | 40 | settings-tp: 41 | image: hyperledger/sawtooth-settings-tp:1.0 42 | depends_on: 43 | - validator 44 | command: settings-tp -vv --connect tcp://validator:4004 45 | 46 | rest-api: 47 | image: hyperledger/sawtooth-rest-api:1.0 48 | expose: 49 | - 4004 50 | - 8080 51 | depends_on: 52 | - validator 53 | entrypoint: | 54 | sawtooth-rest-api -vv 55 | --connect tcp://validator:4004 56 | --bind rest-api:8080 57 | 58 | validator: 59 | image: hyperledger/sawtooth-validator:1.0 60 | ports: 61 | - 4004 62 | - 8800 63 | command: | 64 | bash -c " 65 | if [ ! -f /etc/keys/validator.priv ]; then 66 | sawadm keygen && 67 | sawset genesis \ 68 | -k /etc/sawtooth/keys/validator.priv \ 69 | -o config-genesis.batch && 70 | sawset proposal create \ 71 | -k /etc/sawtooth/keys/validator.priv \ 72 | sawtooth.validator.batch_injectors=block_info \ 73 | -o config.batch && 74 | sawadm genesis config-genesis.batch config.batch 75 | fi; 76 | sawtooth-validator -vv \ 77 | --endpoint tcp://validator:8800 \ 78 | --bind component:tcp://eth0:4004 \ 79 | --bind network:tcp://eth0:8800 80 | " 81 | 82 | seth-timestamp-test: 83 | build: 84 | context: ../../.. 85 | dockerfile: ./cli/Dockerfile 86 | args: 87 | ISOLATION_ID: ${ISOLATION_ID} 88 | image: sawtooth-seth-cli-go:${ISOLATION_ID} 89 | expose: 90 | - 8080 91 | depends_on: 92 | - validator 93 | - rest-api 94 | working_dir: /project/sawtooth-seth/integration/sawtooth_integration/tests 95 | command: test-entrypoint go test seth_timestamp_test.go 96 | stop_signal: SIGKILL 97 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/tests/seth_blockhash_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package tests 19 | 20 | import ( 21 | "encoding/base64" 22 | "encoding/hex" 23 | "fmt" 24 | "net/http" 25 | "github.com/golang/protobuf/proto" 26 | c "seth_cli/client" 27 | . "common" 28 | . "protobuf/block_info_pb2" 29 | "testing" 30 | ) 31 | 32 | const ( 33 | WAIT = 300 34 | PRIV = "274AAF0BFAF68C5F1CB510D2851A71CF720C7218A2C1637D635F6850FF009774" 35 | INIT_BLOCKHASH = "6060604052341561000f57600080fd5b5b60a98061001e6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663c57ffb2d8114603c575b600080fd5b3415604657600080fd5b605967ffffffffffffffff60043516606b565b60405190815260200160405180910390f35b67ffffffffffffffff8116405b9190505600a165627a7a72305820955dfaa8e54445b06e360a47d2f20206fe8d4a59268481286d6207d1cdadcd710029" 36 | BLOCKHASH_1 = "c57ffb2d0000000000000000000000000000000000000000000000000000000000000001" 37 | ) 38 | 39 | // Test getting the blockhash of the first block 40 | func TestBlockHash(t *testing.T) { 41 | client := c.New("http://rest-api:8080") 42 | priv, _ := hex.DecodeString(PRIV) 43 | init, _ := hex.DecodeString(INIT_BLOCKHASH) 44 | nonce := uint64(0) 45 | 46 | // Create the EOA 47 | _, err := client.CreateExternalAccount(priv, nil, nil, 0, WAIT) 48 | if err != nil { 49 | t.Fatal(err.Error()) 50 | } 51 | nonce += 1 52 | 53 | // Create the Contract 54 | contractCreateResult, err := client.CreateContractAccount(priv, init, nil, nonce, 1000, WAIT) 55 | if err != nil { 56 | t.Fatal(err.Error()) 57 | } 58 | nonce += 1 59 | 60 | cmd, _ := hex.DecodeString(BLOCKHASH_1) 61 | contractCallResult, err := client.MessageCall(priv, contractCreateResult.Address, cmd, nonce, 1000, WAIT, false) 62 | blockHash := hex.EncodeToString(contractCallResult.ReturnValue) 63 | 64 | // Get expectedBlockHash of block 1 from BlockInfo 65 | blockInfoAddr, err := NewBlockInfoAddr(1); 66 | if err != nil { 67 | t.Fatal(err.Error()) 68 | } 69 | resp, err := http.Get(fmt.Sprintf("%s/state/%s?wait=%v", client.Url, blockInfoAddr, WAIT)) 70 | if err != nil { 71 | t.Fatal(err.Error()) 72 | } 73 | body, err := c.ParseRespBody(resp) 74 | if err != nil { 75 | t.Fatal(err.Error()) 76 | } 77 | buf, err := base64.StdEncoding.DecodeString(body.Data.(string)) 78 | if err != nil { 79 | t.Fatal(err.Error()) 80 | } 81 | blockInfo := &BlockInfo{} 82 | err = proto.Unmarshal(buf, blockInfo) 83 | expectedBlockHash := blockInfo.GetHeaderSignature()[0:64] 84 | 85 | if expectedBlockHash != blockHash { 86 | t.Fatalf("Incorrect block hash: %s, expected: %s", blockHash, expectedBlockHash) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/tests/seth_blocknum_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package tests 19 | 20 | import ( 21 | "github.com/hyperledger/burrow/binary" 22 | "encoding/base64" 23 | "encoding/hex" 24 | "fmt" 25 | "net/http" 26 | "github.com/golang/protobuf/proto" 27 | c "seth_cli/client" 28 | . "common" 29 | . "protobuf/block_info_pb2" 30 | "testing" 31 | ) 32 | 33 | const ( 34 | WAIT = 300 35 | PRIV = "274AAF0BFAF68C5F1CB510D2851A71CF720C7218A2C1637D635F6850FF009774" 36 | INIT_BLOCKNUM = "60606040523415600e57600080fd5b5b60978061001d6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663503069628114603c575b600080fd5b3415604657600080fd5b604f6004356061565b60405190815260200160405180910390f35b438190035b9190505600a165627a7a723058207ed44310a155801da888f4f3f9d43dea1eeff7828fad8a48a60f7b4364da57070029" 37 | BLOCKNUM_0 = "503069620000000000000000000000000000000000000000000000000000000000000000" 38 | ) 39 | 40 | // Test getting the block number of the current block 41 | func TestBlockNumber(t *testing.T) { 42 | client := c.New("http://rest-api:8080") 43 | priv, _ := hex.DecodeString(PRIV) 44 | init, _ := hex.DecodeString(INIT_BLOCKNUM) 45 | nonce := uint64(0) 46 | 47 | // Create the EOA 48 | _, err := client.CreateExternalAccount(priv, nil, nil, 0, WAIT) 49 | if err != nil { 50 | t.Fatal(err.Error()) 51 | } 52 | nonce += 1 53 | 54 | // Create the Contract 55 | contractCreateResult, err := client.CreateContractAccount(priv, init, nil, nonce, 1000, WAIT) 56 | if err != nil { 57 | t.Fatal(err.Error()) 58 | } 59 | nonce += 1 60 | 61 | cmd, _ := hex.DecodeString(BLOCKNUM_0) 62 | contractCallResult, err := client.MessageCall(priv, contractCreateResult.Address, cmd, nonce, 1000, WAIT, false) 63 | blockNum := binary.Uint64FromWord256(binary.RightPadWord256(contractCallResult.ReturnValue)) 64 | 65 | // Get number of current block from BlockInfo 66 | blockInfoAddr, err := NewBlockInfoAddr(2); 67 | if err != nil { 68 | t.Fatal(err.Error()) 69 | } 70 | resp, err := http.Get(fmt.Sprintf("%s/state/%s?wait=%v", client.Url, blockInfoAddr, WAIT)) 71 | if err != nil { 72 | t.Fatal(err.Error()) 73 | } 74 | body, err := c.ParseRespBody(resp) 75 | if err != nil { 76 | t.Fatal(err.Error()) 77 | } 78 | buf, err := base64.StdEncoding.DecodeString(body.Data.(string)) 79 | if err != nil { 80 | t.Fatal(err.Error()) 81 | } 82 | blockInfo := &BlockInfo{} 83 | err = proto.Unmarshal(buf, blockInfo) 84 | expectedBlockNum := blockInfo.GetBlockNum() 85 | 86 | if expectedBlockNum != blockNum { 87 | t.Fatalf("Incorrect block number: %v, expected: %v", blockNum, expectedBlockNum) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/tests/seth_chaining_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package tests 19 | 20 | import ( 21 | "bytes" 22 | "testing" 23 | c "seth_cli/client" 24 | "encoding/hex" 25 | "github.com/hyperledger/sawtooth-sdk-go/logging" 26 | ) 27 | 28 | const ( 29 | PRIV = "274AAF0BFAF68C5F1CB510D2851A71CF720C7218A2C1637D635F6850FF009774" 30 | INIT_CALLER = "6060604052341561000f57600080fd5b5b6101388061001f6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663b41d7af4811461003d575b600080fd5b341561004857600080fd5b61006973ffffffffffffffffffffffffffffffffffffffff6004351661007b565b60405190815260200160405180910390f35b60008173ffffffffffffffffffffffffffffffffffffffff811663c605f76c83604051602001526040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15156100e957600080fd5b6102c65a03f115156100fa57600080fd5b50505060405180519250505b509190505600a165627a7a72305820ac041b383966301cf39e20d02fd65bd09442a888f34952c12ecfe18c0dc7a3cf0029" 31 | INIT_CALLEE = "6060604052341561000f57600080fd5b5b60af8061001e6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663c605f76c8114603c575b600080fd5b3415604657600080fd5b604c605e565b60405190815260200160405180910390f35b7f68656c6c6f776f726c64000000000000000000000000000000000000000000005b905600a165627a7a723058206daedea9007da979c290c268d5ae84c5b4e1b692c31b6f0abd4d5804a169e0650029" 32 | CALL_HELLO_WORLD = "b41d7af4000000000000000000000000b257af145523371812eb8dfd1b22ddcb18e6a91a" 33 | 34 | WAIT = 300 35 | ) 36 | 37 | var logger *logging.Logger = logging.Get() 38 | 39 | func TestContractChaining(t *testing.T) { 40 | client := c.New("http://rest-api:8080") 41 | priv, _ := hex.DecodeString(PRIV) 42 | init_callee, _ := hex.DecodeString(INIT_CALLEE) 43 | init_caller, _ := hex.DecodeString(INIT_CALLER) 44 | nonce := uint64(0) 45 | 46 | // Create the EOA 47 | _, err := client.CreateExternalAccount(priv, nil, nil, 0, WAIT) 48 | if err != nil { 49 | t.Fatal(err.Error()) 50 | } 51 | nonce += 1 52 | 53 | // Create callee contract 54 | _, err = client.CreateContractAccount(priv, init_callee, nil, nonce, 1000, WAIT) 55 | if err != nil { 56 | t.Fatal(err.Error()) 57 | } 58 | nonce += 1 59 | 60 | // Create caller contract 61 | callerContractResult, err := client.CreateContractAccount(priv, init_caller, nil, nonce, 1000, WAIT) 62 | if err != nil { 63 | t.Fatal(err.Error()) 64 | } 65 | nonce += 1 66 | 67 | // Call contract 68 | cmd, _ := hex.DecodeString(CALL_HELLO_WORLD) 69 | callResult, err := client.MessageCall(priv, callerContractResult.Address, cmd, nonce, 1000, WAIT, true) 70 | 71 | // Convert return value to string 72 | n := bytes.IndexByte(callResult.ReturnValue, 0) 73 | value := string(callResult.ReturnValue[:n]) 74 | 75 | // Compare value 76 | if value != "helloworld" { 77 | t.Fatalf("Incorrect return value: '%s', expected 'helloworld'", value) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/tests/seth_client_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package tests 19 | 20 | import ( 21 | "encoding/hex" 22 | c "seth_cli/client" 23 | "testing" 24 | ) 25 | 26 | func TestClient(t *testing.T) { 27 | client := c.New("http://rest-api:8080") 28 | nonexistent, _ := hex.DecodeString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") 29 | 30 | // Tests that looking up a nonce for a non-existent account won't panic. 31 | // See https://jira.hyperledger.org/browse/STL-959 for more info. 32 | client.LookupAccountNonce(nonexistent) 33 | } 34 | -------------------------------------------------------------------------------- /integration/sawtooth_integration/tests/seth_timestamp_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package tests 19 | 20 | import ( 21 | "github.com/hyperledger/burrow/binary" 22 | "encoding/base64" 23 | "encoding/hex" 24 | "fmt" 25 | "net/http" 26 | "github.com/golang/protobuf/proto" 27 | c "seth_cli/client" 28 | . "common" 29 | . "protobuf/block_info_pb2" 30 | "testing" 31 | ) 32 | 33 | const ( 34 | WAIT = 300 35 | PRIV = "274AAF0BFAF68C5F1CB510D2851A71CF720C7218A2C1637D635F6850FF009774" 36 | INIT_TIMESTAMP = "6060604052341561000f57600080fd5b5b60a68061001e6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663ffcfdd768114603c575b600080fd5b3415604657600080fd5b605160043515156063565b60405190815260200160405180910390f35b6000811560705750426074565b5060005b5b9190505600a165627a7a723058207f054877f30897a342148fdfdf717bdeef570ffd8d1f918cf0feca42f50b3e1b0029" 37 | TIMESTAMP = "ffcfdd760000000000000000000000000000000000000000000000000000000000000001" 38 | ) 39 | 40 | // Test getting the timestamp of the current block 41 | func TestBlockNumber(t *testing.T) { 42 | client := c.New("http://rest-api:8080") 43 | priv, _ := hex.DecodeString(PRIV) 44 | init, _ := hex.DecodeString(INIT_TIMESTAMP) 45 | nonce := uint64(0) 46 | 47 | // Create the EOA 48 | _, err := client.CreateExternalAccount(priv, nil, nil, 0, WAIT) 49 | if err != nil { 50 | t.Fatal(err.Error()) 51 | } 52 | nonce += 1 53 | 54 | // Create the Contract 55 | contractCreateResult, err := client.CreateContractAccount(priv, init, nil, nonce, 1000, WAIT) 56 | if err != nil { 57 | t.Fatal(err.Error()) 58 | } 59 | nonce += 1 60 | 61 | cmd, _ := hex.DecodeString(TIMESTAMP) 62 | contractCallResult, err := client.MessageCall(priv, contractCreateResult.Address, cmd, nonce, 1000, WAIT, false) 63 | timestamp := binary.Uint64FromWord256(binary.RightPadWord256(contractCallResult.ReturnValue)) 64 | 65 | // Get number of current block from BlockInfo 66 | blockInfoAddr, err := NewBlockInfoAddr(2); 67 | if err != nil { 68 | t.Fatal(err.Error()) 69 | } 70 | resp, err := http.Get(fmt.Sprintf("%s/state/%s?wait=%v", client.Url, blockInfoAddr, WAIT)) 71 | if err != nil { 72 | t.Fatal(err.Error()) 73 | } 74 | body, err := c.ParseRespBody(resp) 75 | if err != nil { 76 | t.Fatal(err.Error()) 77 | } 78 | buf, err := base64.StdEncoding.DecodeString(body.Data.(string)) 79 | if err != nil { 80 | t.Fatal(err.Error()) 81 | } 82 | blockInfo := &BlockInfo{} 83 | err = proto.Unmarshal(buf, blockInfo) 84 | expectedTimestamp := blockInfo.GetTimestamp() 85 | 86 | if expectedTimestamp != timestamp { 87 | t.Fatalf("Incorrect timestamp: %v, expected: %v", timestamp, expectedTimestamp) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /processor/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | FROM ubuntu:bionic 17 | 18 | RUN apt-get update \ 19 | && apt-get install gnupg -y 20 | 21 | ENV GOPATH=/project/sawtooth-seth/processor 22 | ENV PATH=$PATH:/project/sawtooth-seth/processor/bin:/project/sawtooth-seth/bin:/usr/lib/go-1.11/bin 23 | WORKDIR $GOPATH/src/seth_tp 24 | 25 | RUN \ 26 | if [ ! -z $HTTP_PROXY ] && [ -z $http_proxy ]; then \ 27 | http_proxy=$HTTP_PROXY; \ 28 | fi; \ 29 | if [ ! -z $HTTPS_PROXY ] && [ -z $https_proxy ]; then \ 30 | https_proxy=$HTTPS_PROXY; \ 31 | fi 32 | 33 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 34 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 35 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 308C15A29AD198E9 \ 36 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 308C15A29AD198E9) \ 37 | && echo 'deb http://repo.sawtooth.me/ubuntu/nightly bionic universe' >> /etc/apt/sources.list \ 38 | && echo 'deb http://ppa.launchpad.net/gophers/archive/ubuntu bionic main' >> /etc/apt/sources.list \ 39 | && apt-get update \ 40 | && apt-get install -y -q \ 41 | git \ 42 | golang-1.11-go \ 43 | libssl-dev \ 44 | libzmq3-dev \ 45 | openssl \ 46 | python3 \ 47 | python3-grpcio-tools \ 48 | && apt-get clean \ 49 | && rm -rf /var/lib/apt/lists/* 50 | 51 | RUN \ 52 | if [ ! -z $http_proxy ]; then \ 53 | git config --global http.proxy $http_proxy; \ 54 | fi; \ 55 | if [ ! -z $https_proxy ]; then \ 56 | git config --global https.proxy $https_proxy; \ 57 | fi 58 | 59 | RUN git config --global url."https://".insteadOf git:// 60 | 61 | RUN go get -u \ 62 | github.com/btcsuite/btcd/btcec \ 63 | github.com/golang/mock/gomock \ 64 | github.com/golang/mock/mockgen \ 65 | github.com/golang/protobuf/proto \ 66 | github.com/golang/protobuf/protoc-gen-go \ 67 | github.com/jessevdk/go-flags \ 68 | github.com/pebbe/zmq4 \ 69 | github.com/satori/go.uuid \ 70 | golang.org/x/crypto/ripemd160 \ 71 | gopkg.in/fatih/set.v0 72 | 73 | RUN git clone https://github.com/knkski/burrow.git $GOPATH/src/github.com/hyperledger/burrow 74 | 75 | RUN go get github.com/hyperledger/sawtooth-sdk-go 76 | 77 | COPY . /project/sawtooth-seth 78 | 79 | RUN seth-protogen go 80 | 81 | ENV GOPATH=$GOPATH/src/github.com/hyperledger/sawtooth-sdk-go:$GOPATH:/project/sawtooth-seth/burrow:/project/sawtooth-seth/common 82 | RUN go build -o /project/sawtooth-seth/processor/bin/seth-tp 83 | -------------------------------------------------------------------------------- /processor/Dockerfile-installed-xenial: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | FROM ubuntu:xenial 17 | 18 | ENV GOPATH=/project/sawtooth-seth/processor 19 | ENV PATH=$PATH:/project/sawtooth-seth/processor/bin:/project/sawtooth-seth/bin:/usr/lib/go-1.11/bin 20 | WORKDIR $GOPATH/src/seth_tp 21 | 22 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD 9AD198E9 \ 23 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD 9AD198E9) \ 24 | && echo 'deb http://repo.sawtooth.me/ubuntu/bumper/stable xenial universe' >> /etc/apt/sources.list \ 25 | && echo 'deb http://ppa.launchpad.net/gophers/archive/ubuntu xenial main' >> /etc/apt/sources.list \ 26 | && apt-get update \ 27 | && apt-get install -y -q \ 28 | git \ 29 | golang-1.11-go \ 30 | libssl-dev \ 31 | libzmq3-dev \ 32 | openssl \ 33 | python3 \ 34 | python3-grpcio-tools=1.1.3-1 \ 35 | && apt-get clean \ 36 | && rm -rf /var/lib/apt/lists/* 37 | 38 | RUN go get -u \ 39 | github.com/btcsuite/btcd/btcec \ 40 | github.com/golang/mock/gomock \ 41 | github.com/golang/mock/mockgen \ 42 | github.com/golang/protobuf/proto \ 43 | github.com/golang/protobuf/protoc-gen-go \ 44 | github.com/jessevdk/go-flags \ 45 | github.com/pebbe/zmq4 \ 46 | github.com/satori/go.uuid \ 47 | golang.org/x/crypto/ripemd160 \ 48 | gopkg.in/fatih/set.v0 49 | 50 | RUN git clone https://github.com/knkski/burrow.git $GOPATH/src/github.com/hyperledger/burrow 51 | 52 | RUN go get github.com/hyperledger/sawtooth-sdk-go 53 | 54 | COPY . /project/sawtooth-seth 55 | 56 | RUN seth-protogen go 57 | 58 | ENV GOPATH=$GOPATH/src/github.com/hyperledger/sawtooth-sdk-go:$GOPATH:/project/sawtooth-seth/burrow:/project/sawtooth-seth/common 59 | RUN go build -o /project/sawtooth-seth/processor/bin/seth-tp 60 | 61 | WORKDIR /project/sawtooth-seth/processor 62 | 63 | RUN pkg_dir=/project/build/debs/ \ 64 | && CHANGELOG_DIR="debian/usr/share/doc/sawtooth-seth" \ 65 | && if [ -d "debian" ]; then rm -rf debian; fi \ 66 | && mkdir -p $pkg_dir \ 67 | && mkdir -p debian/DEBIAN \ 68 | && mkdir -p $CHANGELOG_DIR \ 69 | && cp packaging/ubuntu/* debian \ 70 | && cp debian/changelog $CHANGELOG_DIR \ 71 | && mv debian/changelog $CHANGELOG_DIR/changelog.Debian \ 72 | && gzip --best $CHANGELOG_DIR/changelog \ 73 | && gzip --best $CHANGELOG_DIR/changelog.Debian \ 74 | && mv debian/control debian/DEBIAN \ 75 | # && mv debian/postinst debian/DEBIAN \ 76 | && PACKAGENAME=$(awk '/^Package:/ { print $2 }' debian/DEBIAN/control) \ 77 | && PACKAGEVERSION=$(dpkg-parsechangelog -S version -l $CHANGELOG_DIR/changelog.gz) \ 78 | && PACKAGEARCH=$(dpkg-architecture -qDEB_BUILD_ARCH) \ 79 | && mkdir debian/usr/bin \ 80 | && cp -R bin/seth-tp debian/usr/bin \ 81 | # && cp -R packaging/systemd/* debian/ \ 82 | && fakeroot dpkg-deb --build debian \ 83 | && mv debian.deb $pkg_dir/"${PACKAGENAME}_${PACKAGEVERSION}_${PACKAGEARCH}.deb" 84 | 85 | FROM ubuntu:xenial 86 | 87 | RUN mkdir /debs 88 | 89 | COPY --from=0 /project/build/debs/sawtooth-seth-tp_*amd64.deb /debs 90 | 91 | RUN apt-get update \ 92 | && apt-get install -y -q \ 93 | dpkg-dev \ 94 | && cd /debs \ 95 | && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz \ 96 | && echo "deb file:/debs ./" >> /etc/apt/sources.list \ 97 | && apt-get update \ 98 | && apt-get install sawtooth-seth-tp -y -q --allow-unauthenticated \ 99 | && apt-get clean \ 100 | && rm -rf /var/lib/apt/lists/* 101 | -------------------------------------------------------------------------------- /processor/packaging/ubuntu/changelog: -------------------------------------------------------------------------------- 1 | sawtooth-seth-tp (0.2.0) unstable; urgency=low 2 | 3 | * change data here 4 | 5 | -- Hyperledger Sawtooth 6 | -------------------------------------------------------------------------------- /processor/packaging/ubuntu/control: -------------------------------------------------------------------------------- 1 | Source: sawtooth-seth-tp 2 | Maintainer: Hyperledger Sawtooth 3 | Section: go 4 | Priority: optional 5 | Standards-Version: 3.9.6 6 | Homepage: https://github.com/hyperledger/sawtooth-seth 7 | Package: sawtooth-seth-tp 8 | Architecture: all 9 | Depends: libssl-dev, libzmq3-dev 10 | Description: Sawtooth Seth Transaction Processor 11 | Version: 0.2.0 12 | -------------------------------------------------------------------------------- /processor/src/seth_tp/handler/sawtooth_event_fireable.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package handler 19 | 20 | import ( 21 | "encoding/hex" 22 | "fmt" 23 | "github.com/hyperledger/burrow/execution/errors" 24 | "github.com/hyperledger/burrow/execution/exec" 25 | "github.com/hyperledger/sawtooth-sdk-go/processor" 26 | ) 27 | 28 | type SawtoothEventFireable struct { 29 | context *processor.Context 30 | } 31 | 32 | func NewSawtoothEventFireable(context *processor.Context) *SawtoothEventFireable { 33 | return &SawtoothEventFireable{ 34 | context: context, 35 | } 36 | } 37 | 38 | func (evc *SawtoothEventFireable) Call(call *exec.CallEvent, exception *errors.Exception) { 39 | // Not used 40 | } 41 | 42 | func (evc *SawtoothEventFireable) Log(log *exec.LogEvent) { 43 | attributes := []processor.Attribute{ 44 | { 45 | Key: "address", 46 | Value: hex.EncodeToString(log.Address.Bytes()), 47 | }, 48 | { 49 | Key: "eventID", 50 | Value: log.Address.String(), 51 | }, 52 | } 53 | for i, topic := range log.Topics { 54 | attributes = append(attributes, processor.Attribute{ 55 | Key: fmt.Sprintf("topic%v", i+1), 56 | Value: hex.EncodeToString(topic.Bytes()), 57 | }) 58 | } 59 | evc.context.AddEvent("seth_log_event", attributes, log.Data) 60 | } 61 | -------------------------------------------------------------------------------- /processor/src/seth_tp/main.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/hyperledger/sawtooth-sdk-go/logging" 23 | "github.com/hyperledger/sawtooth-sdk-go/processor" 24 | "github.com/jessevdk/go-flags" 25 | "os" 26 | seth "seth_tp/handler" 27 | "syscall" 28 | ) 29 | 30 | type Opts struct { 31 | Verbose []bool `short:"v" long:"verbose" description:"Increase verbosity"` 32 | Connect string `short:"C" long:"connect" description:"Validator component endpoint to connect to" default:"tcp://localhost:4004"` 33 | } 34 | 35 | func main() { 36 | var opts Opts 37 | 38 | logger := logging.Get() 39 | 40 | parser := flags.NewParser(&opts, flags.Default) 41 | remaining, err := parser.Parse() 42 | if err != nil { 43 | if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { 44 | os.Exit(0) 45 | } else { 46 | logger.Errorf("Failed to parse args: %v", err) 47 | os.Exit(2) 48 | } 49 | } 50 | 51 | if len(remaining) > 0 { 52 | fmt.Printf("Error: Unrecognized arguments passed: %v\n", remaining) 53 | os.Exit(2) 54 | } 55 | 56 | endpoint := opts.Connect 57 | 58 | switch len(opts.Verbose) { 59 | case 2: 60 | logger.SetLevel(logging.DEBUG) 61 | case 1: 62 | logger.SetLevel(logging.INFO) 63 | default: 64 | logger.SetLevel(logging.WARN) 65 | } 66 | 67 | handler := seth.NewBurrowEVMHandler() 68 | processor := processor.NewTransactionProcessor(endpoint) 69 | processor.AddHandler(handler) 70 | processor.ShutdownOnSignal(syscall.SIGINT, syscall.SIGTERM) 71 | err = processor.Start() 72 | if err != nil { 73 | logger.Error("Processor stopped: ", err) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /protos/block_info.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Intel Corporation 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // ----------------------------------------------------------------------------- 15 | 16 | syntax = "proto3"; 17 | 18 | option java_multiple_files = true; 19 | option java_package = "sawtooth.block_info.protobuf"; 20 | option go_package = "block_info_pb2"; 21 | 22 | message BlockInfoConfig { 23 | uint64 latest_block = 1; 24 | uint64 oldest_block = 2; 25 | uint64 target_count = 3; 26 | uint64 sync_tolerance = 4; 27 | } 28 | 29 | message BlockInfo { 30 | // Block number in the chain 31 | uint64 block_num = 1; 32 | // The header_signature of the previous block that was added to the chain. 33 | string previous_block_id = 2; 34 | // Public key for the component internal to the validator that 35 | // signed the BlockHeader 36 | string signer_public_key = 3; 37 | // The signature derived from signing the header 38 | string header_signature = 4; 39 | // Approximately when this block was committed, as a Unix UTC timestamp 40 | uint64 timestamp = 5; 41 | } 42 | 43 | message BlockInfoTxn { 44 | // The new block to add to state 45 | BlockInfo block = 1; 46 | // If this is set, the new target number of blocks to store in state 47 | uint64 target_count = 2; 48 | // If set, the new network time synchronization tolerance. 49 | uint64 sync_tolerance = 3; 50 | } 51 | -------------------------------------------------------------------------------- /rpc/Cargo.toml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | [package] 17 | name = "sawtooth-seth-rpc" 18 | version = "0.2.4" 19 | authors = ["sawtooth"] 20 | 21 | [[bin]] 22 | name = "seth-rpc" 23 | path = "src/main.rs" 24 | 25 | [dependencies] 26 | clap = "2" 27 | dirs = "2" 28 | futures-cpupool = "0.1" 29 | jsonrpc-core = "12.0" 30 | jsonrpc-http-server = "12.0" 31 | log = "0.4" 32 | protobuf = "2" 33 | rust-crypto = "0.2" 34 | sawtooth-sdk = "0.3" 35 | serde_json = "1.0" 36 | simple-logging = "2.0" 37 | tiny-keccak = "1.4" 38 | uuid = { version = "0.7", features = ["v4"] } 39 | 40 | [build-dependencies] 41 | cc = "1.0" 42 | glob = "0.3" 43 | protoc-rust = "2.0" 44 | -------------------------------------------------------------------------------- /rpc/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | FROM ubuntu:bionic 17 | 18 | RUN apt-get update \ 19 | && apt-get install gnupg -y 20 | 21 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 22 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 23 | && echo 'deb http://repo.sawtooth.me/ubuntu/nightly bionic universe' >> /etc/apt/sources.list \ 24 | && apt-get update \ 25 | && apt-get install -y -q \ 26 | curl \ 27 | gcc \ 28 | git \ 29 | libssl-dev \ 30 | libzmq3-dev \ 31 | openssl \ 32 | pkg-config \ 33 | python3 \ 34 | python3-grpcio-tools \ 35 | unzip \ 36 | && curl -s -S -o /tmp/setup-node.sh https://deb.nodesource.com/setup_6.x \ 37 | && chmod 755 /tmp/setup-node.sh \ 38 | && /tmp/setup-node.sh \ 39 | && apt-get install nodejs -y -q \ 40 | && rm /tmp/setup-node.sh \ 41 | && apt-get clean \ 42 | && rm -rf /var/lib/apt/lists/* 43 | 44 | RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \ 45 | && unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \ 46 | && rm protoc-3.5.1-linux-x86_64.zip 47 | 48 | RUN curl https://sh.rustup.rs -sSf > /usr/bin/rustup-init \ 49 | && chmod +x /usr/bin/rustup-init \ 50 | && rustup-init -y 51 | 52 | ENV PATH=$PATH:/project/sawtooth-seth/bin:/root/.cargo/bin:/protoc3/bin \ 53 | CARGO_INCREMENTAL=0 54 | 55 | RUN rustup component add clippy && \ 56 | rustup component add rustfmt 57 | 58 | WORKDIR /project/sawtooth-seth/rpc 59 | 60 | COPY bin/ /project/sawtooth-seth/bin 61 | COPY protos/ /project/sawtooth-seth/protos 62 | COPY rpc/ /project/sawtooth-seth/rpc 63 | COPY tests/ /project/sawtooth-seth/tests 64 | 65 | RUN cargo build && cp ./target/debug/seth-rpc /project/sawtooth-seth/bin/seth-rpc 66 | -------------------------------------------------------------------------------- /rpc/Dockerfile-installed-bionic: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # Copyright 2019 Cargill Incorporated 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ------------------------------------------------------------------------------ 16 | 17 | # -------------=== seth rpc build ===------------- 18 | 19 | FROM ubuntu:bionic 20 | 21 | ENV VERSION=AUTO_STRICT 22 | 23 | RUN apt-get update \ 24 | && apt-get install gnupg -y 25 | 26 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 27 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 28 | && echo 'deb http://repo.sawtooth.me/ubuntu/nightly bionic universe' >> /etc/apt/sources.list \ 29 | && apt-get update \ 30 | && apt-get install -y -q \ 31 | curl \ 32 | gcc \ 33 | git \ 34 | libssl-dev \ 35 | libzmq3-dev \ 36 | openssl \ 37 | pkg-config \ 38 | python3 \ 39 | python3-grpcio-tools \ 40 | unzip \ 41 | && curl -s -S -o /tmp/setup-node.sh https://deb.nodesource.com/setup_6.x \ 42 | && chmod 755 /tmp/setup-node.sh \ 43 | && /tmp/setup-node.sh \ 44 | && apt-get install nodejs -y -q \ 45 | && rm /tmp/setup-node.sh \ 46 | && apt-get clean \ 47 | && rm -rf /var/lib/apt/lists/* 48 | 49 | RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \ 50 | && unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \ 51 | && rm protoc-3.5.1-linux-x86_64.zip 52 | 53 | RUN curl https://sh.rustup.rs -sSf > /usr/bin/rustup-init \ 54 | && chmod +x /usr/bin/rustup-init \ 55 | && rustup-init -y 56 | 57 | ENV PATH=$PATH:/project/sawtooth-seth/bin:/root/.cargo/bin:/protoc3/bin:/project/sawtooth-seth/rpc/bin \ 58 | CARGO_INCREMENTAL=0 59 | 60 | RUN /root/.cargo/bin/cargo install cargo-deb 61 | 62 | COPY . /project 63 | 64 | WORKDIR /project/rpc 65 | 66 | RUN export VERSION=$(../bin/get_version) \ 67 | && sed -i -e "0,/version.*$/ s/version.*$/version\ =\ \"${VERSION}\"/" Cargo.toml \ 68 | && /root/.cargo/bin/cargo deb --deb-version $VERSION 69 | 70 | # -------------=== seth rpc docker build ===------------- 71 | 72 | FROM ubuntu:bionic 73 | 74 | RUN mkdir /debs 75 | 76 | COPY --from=0 /project/target/debian/sawtooth-seth-rpc_*amd64.deb /debs 77 | 78 | RUN apt-get update \ 79 | && dpkg -i /debs/sawtooth-seth-rpc_*amd64.deb || true \ 80 | && apt-get -f -y install \ 81 | && apt-get clean \ 82 | && rm -rf /var/lib/apt/lists/* 83 | -------------------------------------------------------------------------------- /rpc/Dockerfile-installed-xenial: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | FROM ubuntu:xenial 17 | 18 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 19 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 20 | && echo 'deb http://repo.sawtooth.me/ubuntu/bumper/stable xenial universe' >> /etc/apt/sources.list \ 21 | && apt-get update \ 22 | && apt-get install -y -q \ 23 | curl \ 24 | gcc \ 25 | git \ 26 | libssl-dev \ 27 | libzmq3-dev \ 28 | openssl \ 29 | pkg-config \ 30 | python3 \ 31 | python3-grpcio-tools=1.1.3-1 \ 32 | unzip \ 33 | && curl -s -S -o /tmp/setup-node.sh https://deb.nodesource.com/setup_6.x \ 34 | && chmod 755 /tmp/setup-node.sh \ 35 | && /tmp/setup-node.sh \ 36 | && apt-get install nodejs -y -q \ 37 | && rm /tmp/setup-node.sh \ 38 | && apt-get clean \ 39 | && rm -rf /var/lib/apt/lists/* 40 | 41 | RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip \ 42 | && unzip protoc-3.5.1-linux-x86_64.zip -d protoc3 \ 43 | && rm protoc-3.5.1-linux-x86_64.zip 44 | 45 | RUN curl https://sh.rustup.rs -sSf > /usr/bin/rustup-init \ 46 | && chmod +x /usr/bin/rustup-init \ 47 | && rustup-init -y 48 | 49 | ENV PATH=$PATH:/project/sawtooth-seth/bin:/root/.cargo/bin:/protoc3/bin:/project/sawtooth-seth/rpc/bin \ 50 | CARGO_INCREMENTAL=0 51 | 52 | WORKDIR /project/sawtooth-seth/rpc 53 | 54 | COPY bin/ /project/sawtooth-seth/bin 55 | COPY protos/ /project/sawtooth-seth/protos 56 | COPY rpc/ /project/sawtooth-seth/rpc 57 | COPY tests/ /project/sawtooth-seth/tests 58 | 59 | RUN mkdir /project/sawtooth-seth/rpc/bin \ 60 | && cargo build \ 61 | && cp ./target/debug/rpc /project/sawtooth-seth/rpc/bin/seth-rpc 62 | 63 | RUN pkg_dir=/project/build/debs/ \ 64 | && CHANGELOG_DIR="debian/usr/share/doc/sawtooth-seth" \ 65 | && if [ -d "debian" ]; then rm -rf debian; fi \ 66 | && mkdir -p $pkg_dir \ 67 | && mkdir -p debian/DEBIAN \ 68 | && mkdir -p $CHANGELOG_DIR \ 69 | && cp packaging/ubuntu/* debian \ 70 | && cp debian/changelog $CHANGELOG_DIR \ 71 | && mv debian/changelog $CHANGELOG_DIR/changelog.Debian \ 72 | && gzip --best $CHANGELOG_DIR/changelog \ 73 | && gzip --best $CHANGELOG_DIR/changelog.Debian \ 74 | && mv debian/control debian/DEBIAN \ 75 | # && mv debian/postinst debian/DEBIAN \ 76 | && PACKAGENAME=$(awk '/^Package:/ { print $2 }' debian/DEBIAN/control) \ 77 | && PACKAGEVERSION=$(dpkg-parsechangelog -S version -l $CHANGELOG_DIR/changelog.gz) \ 78 | && PACKAGEARCH=$(dpkg-architecture -qDEB_BUILD_ARCH) \ 79 | && mkdir debian/usr/bin \ 80 | && cp -R bin/seth-rpc debian/usr/bin \ 81 | # && cp -R packaging/systemd/* debian/ \ 82 | && fakeroot dpkg-deb --build debian \ 83 | && mv debian.deb $pkg_dir/"${PACKAGENAME}_${PACKAGEVERSION}_${PACKAGEARCH}.deb" 84 | 85 | FROM ubuntu:xenial 86 | 87 | RUN mkdir /debs 88 | 89 | COPY --from=0 /project/build/debs/sawtooth-seth-rpc_*amd64.deb /debs 90 | 91 | RUN apt-get update \ 92 | && apt-get install -y -q \ 93 | dpkg-dev \ 94 | && cd /debs \ 95 | && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz \ 96 | && echo "deb file:/debs ./" >> /etc/apt/sources.list \ 97 | && apt-get update \ 98 | && apt-get install sawtooth-seth-rpc -y -q --allow-unauthenticated \ 99 | && apt-get clean \ 100 | && rm -rf /var/lib/apt/lists/* 101 | -------------------------------------------------------------------------------- /rpc/build.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Intel Corporation 3 | * Copyright 2018-2020 Cargill Incorporated 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ------------------------------------------------------------------------------ 17 | */ 18 | 19 | extern crate glob; 20 | extern crate protoc_rust; 21 | 22 | use std::env; 23 | use std::fs; 24 | use std::fs::File; 25 | use std::io::Write; 26 | use std::path::Path; 27 | 28 | use protoc_rust::Customize; 29 | 30 | fn main() { 31 | // Generate protobuf files 32 | let proto_src_files = glob_simple("../protos/*.proto"); 33 | println!("{:?}", proto_src_files); 34 | 35 | let out_dir = env::var("OUT_DIR").expect("No OUT_DIR env variable"); 36 | let dest_path = Path::new(&out_dir).join("protos"); 37 | fs::create_dir_all(&dest_path).expect("Unable to create proto destination directory"); 38 | 39 | let mod_file_content = proto_src_files 40 | .iter() 41 | .map(|proto_file| { 42 | let proto_path = Path::new(proto_file); 43 | format!( 44 | "pub mod {};", 45 | proto_path 46 | .file_stem() 47 | .expect("Unable to extract stem") 48 | .to_str() 49 | .expect("Unable to extract filename") 50 | ) 51 | }) 52 | .collect::>() 53 | .join("\n"); 54 | 55 | let mut mod_file = File::create(dest_path.join("mod.rs")).unwrap(); 56 | mod_file 57 | .write_all(mod_file_content.as_bytes()) 58 | .expect("Unable to write mod file"); 59 | 60 | protoc_rust::Codegen::new() 61 | .out_dir(&dest_path.to_str().expect("Invalid proto destination path")) 62 | .inputs( 63 | &proto_src_files 64 | .iter() 65 | .map(|a| a.as_ref()) 66 | .collect::>(), 67 | ) 68 | .includes(&["../protos"]) 69 | .customize(Customize::default()) 70 | .run() 71 | .expect("unable to run protoc"); 72 | } 73 | 74 | fn glob_simple(pattern: &str) -> Vec { 75 | glob::glob(pattern) 76 | .expect("glob") 77 | .map(|g| { 78 | g.expect("item") 79 | .as_path() 80 | .to_str() 81 | .expect("utf-8") 82 | .to_owned() 83 | }) 84 | .collect() 85 | } 86 | -------------------------------------------------------------------------------- /rpc/comp_seth_rpc.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: "2.1" 17 | 18 | services: 19 | seth-rpc: 20 | build: 21 | context: .. 22 | dockerfile: ./rpc/Dockerfile 23 | args: 24 | ISOLATION_ID: ${ISOLATION_ID} 25 | image: sawtooth-seth-rpc:${ISOLATION_ID} 26 | working_dir: /project/sawtooth-seth/rpc 27 | expose: 28 | - 3030 29 | - 4004 30 | environment: 31 | RUST_BACKTRACE: 1 32 | command: "bash -c \" 33 | mkdir -p ~/.sawtooth/keys/ && 34 | cp tests/data/test.pem ~/.sawtooth/keys/test.pem && 35 | cargo run -- 36 | --connect tcp://comp-seth-rpc:4004 37 | --bind 0.0.0.0:3030 38 | -v 39 | --unlock test\"" 40 | 41 | comp-seth-rpc: 42 | build: 43 | context: .. 44 | dockerfile: ./rpc/tests/Dockerfile 45 | args: 46 | ISOLATION_ID: ${ISOLATION_ID} 47 | image: rpc-test-python:${ISOLATION_ID} 48 | expose: 49 | - 4004 50 | command: nose2-3 51 | -c /project/sawtooth-seth/rpc/tests/nose2.cfg 52 | -v 53 | -s /project/sawtooth-seth/rpc/tests 54 | --fail-fast 55 | -------------------------------------------------------------------------------- /rpc/packaging/ubuntu/changelog: -------------------------------------------------------------------------------- 1 | sawtooth-seth-rpc (0.2.0) unstable; urgency=low 2 | 3 | * change data here 4 | 5 | -- Hyperledger Sawtooth 6 | -------------------------------------------------------------------------------- /rpc/packaging/ubuntu/control: -------------------------------------------------------------------------------- 1 | Source: sawtooth-seth-rpc 2 | Maintainer: Hyperledger Sawtooth 3 | Section: rust 4 | Priority: optional 5 | Standards-Version: 3.9.6 6 | Homepage: https://github.com/hyperledger/sawtooth-seth 7 | Package: sawtooth-seth-rpc 8 | Architecture: all 9 | Depends: libssl-dev, libzmq3-dev 10 | Description: Sawtooth Seth RPC 11 | Version: 0.2.0 12 | -------------------------------------------------------------------------------- /rpc/src/calls/error.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | use jsonrpc_core::{Error, ErrorCode}; 19 | 20 | pub fn not_implemented() -> Error { 21 | Error { 22 | code: ErrorCode::ServerError(-1), 23 | message: String::from("Method not implemented"), 24 | data: None, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /rpc/src/calls/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | #![allow(unknown_lints)] 18 | 19 | pub mod account; 20 | pub mod block; 21 | pub mod error; 22 | pub mod logs; 23 | pub mod network; 24 | pub mod personal; 25 | pub mod seth; 26 | pub mod transaction; 27 | -------------------------------------------------------------------------------- /rpc/src/calls/network.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | use jsonrpc_core::{Error, Params, Value}; 19 | 20 | use client::ValidatorClient; 21 | use requests::RequestHandler; 22 | 23 | use sawtooth_sdk::messaging::stream::MessageSender; 24 | 25 | const SAWTOOTH_NET_VERSION: &str = "19"; 26 | 27 | pub fn get_method_list() -> Vec<(String, RequestHandler)> 28 | where 29 | T: MessageSender, 30 | { 31 | vec![ 32 | ("net_version".into(), version), 33 | ("net_peerCount".into(), peer_count), 34 | ("net_listening".into(), listening), 35 | ] 36 | } 37 | 38 | // Version refers to the particular network this JSON-RPC client is connected to 39 | pub fn version(_params: Params, _client: ValidatorClient) -> Result 40 | where 41 | T: MessageSender, 42 | { 43 | info!("net_version"); 44 | Ok(Value::String(String::from(SAWTOOTH_NET_VERSION))) 45 | } 46 | 47 | // Return the number of actual Sawtooth peers 48 | pub fn peer_count(_params: Params, client: ValidatorClient) -> Result 49 | where 50 | T: MessageSender, 51 | { 52 | info!("net_peerCount"); 53 | let n = match client.get_peers() { 54 | Err(_) => 0, 55 | Ok(n) => n, 56 | }; 57 | 58 | Ok(Value::String(format!("{:#x}", n))) 59 | } 60 | 61 | // Return whether we are listening for connections, which is always true 62 | pub fn listening(_params: Params, _client: ValidatorClient) -> Result 63 | where 64 | T: MessageSender, 65 | { 66 | info!("net_listening"); 67 | Ok(Value::Bool(true)) 68 | } 69 | -------------------------------------------------------------------------------- /rpc/src/calls/seth.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | use client::{BlockKey, ValidatorClient}; 19 | use jsonrpc_core::{Error, Params, Value}; 20 | use messages::seth::EvmPermissions; 21 | use messages::seth::SetPermissionsTxn; 22 | use messages::seth::SethTransaction as SethTransactionPb; 23 | use messages::seth::SethTransaction_TransactionType; 24 | use requests::RequestHandler; 25 | use sawtooth_sdk::messaging::stream::MessageSender; 26 | use std::time::{SystemTime, UNIX_EPOCH}; 27 | use transactions::SethTransaction; 28 | use transform; 29 | 30 | pub fn get_method_list() -> Vec<(String, RequestHandler)> 31 | where 32 | T: MessageSender, 33 | { 34 | vec![ 35 | ("seth_getPermissions".into(), get_permissions), 36 | ("seth_setPermissions".into(), set_permissions), 37 | ] 38 | } 39 | 40 | pub fn get_permissions(params: Params, client: ValidatorClient) -> Result 41 | where 42 | T: MessageSender, 43 | { 44 | info!("seth_getPermissions"); 45 | 46 | let usage = "Takes [address: ADDRESS]"; 47 | 48 | let (address,): (String,) = params.parse().map_err(|_| Error::invalid_params(usage))?; 49 | 50 | let account = client 51 | .get_account(&address, BlockKey::Latest) 52 | .map_err(|err| fail!("Couldn't get key", err))?; 53 | 54 | match account { 55 | Some(a) => Ok(Value::String(format!("{}", a.get_permissions()))), 56 | None => Ok(Value::Null), 57 | } 58 | } 59 | 60 | pub fn set_permissions(params: Params, client: ValidatorClient) -> Result 61 | where 62 | T: MessageSender, 63 | { 64 | info!("seth_setPermissions"); 65 | 66 | let usage = "Takes [address: ADDRESS, permissions: DATA]"; 67 | 68 | let (address, permissions): (String, String) = 69 | params.parse().map_err(|_| Error::invalid_params(usage))?; 70 | 71 | let nonce = SystemTime::now() 72 | .duration_since(UNIX_EPOCH) 73 | .map_err(|err| fail!("Time has gone backwards", err))? 74 | .as_secs(); 75 | 76 | // Create and send the transaction in for processing 77 | let mut txn = SethTransactionPb::new(); 78 | txn.set_transaction_type(SethTransaction_TransactionType::SET_PERMISSIONS); 79 | txn.set_set_permissions({ 80 | let mut inner = SetPermissionsTxn::new(); 81 | inner.set_nonce(nonce); 82 | inner.set_to( 83 | transform::hex_str_to_bytes(&address).ok_or_else(|| Error::invalid_params(usage))?, 84 | ); 85 | inner.set_permissions( 86 | permissions 87 | .parse::() 88 | .map_err(|err| fail!("Couldn't parse permissions", err))?, 89 | ); 90 | inner 91 | }); 92 | 93 | client 94 | .send_transaction( 95 | &client 96 | .unlocked_account() 97 | .ok_or_else(|| fail!("Couldn't unlock account"))? 98 | .public_key(), 99 | &SethTransaction::try_from(txn).ok_or_else(|| fail!("Couldn't create transaction"))?, 100 | ) 101 | .map_err(|err| fail!("Couldn't send transaction", err))?; 102 | 103 | Ok(Value::Bool(true)) 104 | } 105 | -------------------------------------------------------------------------------- /rpc/src/messages/mod.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | include!(concat!(env!("OUT_DIR"), "/protos/mod.rs")); 19 | 20 | use std::fmt; 21 | use std::str::FromStr; 22 | 23 | use self::seth::EvmPermissions; 24 | 25 | impl FromStr for EvmPermissions { 26 | type Err = String; 27 | 28 | fn from_str(s: &str) -> Result { 29 | let mut permissions = EvmPermissions::new(); 30 | 31 | for perm in s.split(',') { 32 | let mut chars = perm.chars(); 33 | let modifier = chars 34 | .next() 35 | .ok_or_else(|| String::from("Found an empty string instead of a permission!"))?; 36 | let name = chars.collect::(); 37 | 38 | let perm_bit = match name.as_str() { 39 | "all" => 1 | 2 | 4 | 8 | 16, 40 | "root" => 1, 41 | "send" => 2, 42 | "call" => 4, 43 | "contract" => 8, 44 | "account" => 16, 45 | _ => return Err(format!("Unknown permission `{}`", name)), 46 | }; 47 | 48 | match modifier { 49 | '+' => permissions.perms |= perm_bit, 50 | '-' => permissions.perms &= !perm_bit, 51 | _ => return Err(format!("Bad modifier `{}`", modifier)), 52 | } 53 | } 54 | 55 | Ok(permissions) 56 | } 57 | } 58 | 59 | impl fmt::Display for EvmPermissions { 60 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 61 | let perms = [ 62 | ("root", 1), 63 | ("send", 2), 64 | ("call", 4), 65 | ("contract", 8), 66 | ("account", 16), 67 | ]; 68 | 69 | let perms_str = perms 70 | .iter() 71 | .map(|(name, bit)| format!("{}{}", if self.perms & bit == 0 { "-" } else { "+" }, name)) 72 | .collect::>() 73 | .join(","); 74 | 75 | fmt.write_str(&perms_str)?; 76 | Ok(()) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /rpc/src/requests.rs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | use super::client::ValidatorClient; 19 | use futures_cpupool::CpuPool; 20 | use jsonrpc_core::{BoxFuture, Error, Params, Value}; 21 | use sawtooth_sdk::messaging::stream::*; 22 | 23 | pub type RequestHandler = fn(Params, ValidatorClient) -> Result; 24 | 25 | #[derive(Clone)] 26 | pub struct RequestExecutor { 27 | pool: CpuPool, 28 | client: ValidatorClient, 29 | } 30 | 31 | impl RequestExecutor { 32 | pub fn new(client: ValidatorClient) -> Self { 33 | RequestExecutor { 34 | pool: CpuPool::new_num_cpus(), 35 | client, 36 | } 37 | } 38 | 39 | pub fn run(&self, params: Params, handler: RequestHandler) -> BoxFuture { 40 | let client = self.client.clone(); 41 | Box::new(self.pool.spawn_fn(move || handler(params, client))) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rpc/tests/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | FROM ubuntu:bionic 17 | 18 | RUN apt-get update \ 19 | && apt-get install gnupg -y 20 | 21 | RUN (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 22 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 23 | && echo 'deb http://repo.sawtooth.me/ubuntu/nightly bionic universe' >> /etc/apt/sources.list \ 24 | && apt-get update \ 25 | && apt-get install -y -q --allow-unauthenticated \ 26 | python3-grpcio-tools \ 27 | python3-nose2 \ 28 | python3-protobuf \ 29 | python3-requests \ 30 | python3-sawtooth-sdk \ 31 | python3-zmq \ 32 | && apt-get clean \ 33 | && rm -rf /var/lib/apt/lists/* 34 | 35 | COPY . /project/sawtooth-seth 36 | 37 | ENV PATH=$PATH:/project/sawtooth-seth/bin 38 | 39 | RUN seth-protogen 40 | -------------------------------------------------------------------------------- /rpc/tests/data/test.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PRIVATE KEY----- 2 | MC4CAQEEIKYTpX9636xTHDzdjGqdQtUS26BYHC/q4nEWT0FQQ5HIoAcGBSuBBAAK 3 | -----END EC PRIVATE KEY----- 4 | -------------------------------------------------------------------------------- /rpc/tests/rpc_client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | import threading 17 | import time 18 | import requests 19 | 20 | 21 | class RpcClient: 22 | def __init__(self, url): 23 | self.url = url 24 | self.id = 1 25 | self.result = None 26 | self.thread = None 27 | 28 | def wait_for_service(self): 29 | while True: 30 | try: 31 | requests.get(self.url) 32 | return 33 | except requests.ConnectionError: 34 | time.sleep(0.2) 35 | 36 | def call(self, method, params=None): 37 | request = {"jsonrpc": "2.0", "method": method, "id": self.id} 38 | if params: 39 | request["params"] = params 40 | self.id += 1 41 | response = requests.post(self.url, json=request).json() 42 | try: 43 | return response['result'] 44 | except KeyError: 45 | return response 46 | 47 | def acall(self, method, params=None): 48 | def _acall(self): 49 | self.result = self.call(method, params) 50 | self.thread = threading.Thread(target=_acall, args=(self,)) 51 | self.thread.start() 52 | 53 | def get_result(self): 54 | self.thread.join() 55 | return self.result 56 | -------------------------------------------------------------------------------- /tests/addresses_test.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2017 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * ------------------------------------------------------------------------------ 16 | */ 17 | 18 | package tests 19 | 20 | import ( 21 | "encoding/hex" 22 | "testing" 23 | . "common" 24 | ) 25 | 26 | const ( 27 | PRIV = "b66691acf0f79c52462b833b607674ee3fa97a09928b513792782607101de9fe" 28 | ADDR0 = "0187d022ae80d1010a7297fae9c35c15555cdcbf" 29 | ADDR1 = "9e94e37000fd8682acee26e9b4419af4938b2ead" 30 | ADDR2 = "4adcb4c5cc2d634e1c0e2ea97081f2f80eb0537f" 31 | ) 32 | 33 | func check(err error) { 34 | if err != nil { 35 | panic(err.Error()) 36 | } 37 | } 38 | 39 | func TestAddresses(t *testing.T) { 40 | priv, _ := hex.DecodeString(PRIV) 41 | 42 | // Test from private key bytes, public key bytes, and from bytes 43 | ea, err := PrivToEvmAddr(priv) 44 | check(err) 45 | if ea.String() != ADDR0 { 46 | t.Errorf("%v != %v", ea, ADDR0) 47 | } 48 | 49 | // Test from string 50 | ea, err = NewEvmAddrFromString(ADDR0) 51 | check(err) 52 | if ea.String() != ADDR0 { 53 | t.Errorf("%v != %v", ea, ADDR0) 54 | } 55 | 56 | _, err = NewEvmAddrFromString("tyza") 57 | if err == nil { 58 | t.Error("Error expected, but none returned.") 59 | } 60 | 61 | ea1 := ea.Derive(1) 62 | if ea1.String() != ADDR1 { 63 | t.Errorf("%v != %v", ea1, ADDR1) 64 | } 65 | 66 | ea2 := ea.Derive(2) 67 | if ea2.String() != ADDR2 { 68 | t.Errorf("%v != %v", ea2, ADDR2) 69 | } 70 | 71 | if ea2.ToStateAddr().ToEvmAddr().String() != ea2.String() { 72 | t.Errorf("Conversion between StateAddr and EvmAddr failed.") 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/encoder_test.go: -------------------------------------------------------------------------------- 1 | package tests 2 | 3 | import ( 4 | "encoding/hex" 5 | "testing" 6 | . "seth_cli/client" 7 | "github.com/hyperledger/sawtooth-sdk-go/signing" 8 | ) 9 | 10 | var ( 11 | data = []byte{0x01, 0x02, 0x03} 12 | PRIV_HEX = "274AAF0BFAF68C5F1CB510D2851A71CF720C7218A2C1637D635F6850FF009774" 13 | ENCDED="0ab40a0aca020a423033356531646533303438613632663966343738343430613232666437363535623830663061616339393762653936336231313961633534623362666465613362371280013064366530643165323133346462353833316138313964323364376132333835383836613266633063303739663837613630613130323635396237373835613532626364363037333537396537376532663964333936323136393139643134363264666430646538646136373564336233633830333066303632663032353634128001343631313764356234303934393865663265653537663061616338633932623164393831353238636561343731613230633634333963333434666230616235613334363262363830393961326665643734303532343134653034386362306632303032356266626636333736353636313365386464643164666430313164323112800137313265623534646435633965653837616561656633346164646338623765626664353231393865663165356162656466306666306132373863376262633961376439343331643531633636663236613032366336373637333162316166396335363166396131663066623065373530366464656666396162373063626663331aaf030aa4020a423033356531646533303438613632663966343738343430613232666437363535623830663061616339393762653936336231313961633534623362666465613362371a0361626322033132332a0364656632033132333a036465664a80013237383634636335323139613935316137613665353262386338646464663639383164303938646131363538643936323538633837306232633838646662636235313834316165613137326132386261666136613739373331313635353834363737303636303435633935396564306639393239363838643034646566633239524230333565316465333034386136326639663437383434306132326664373635356238306630616163393937626539363362313139616335346233626664656133623712800130643665306431653231333464623538333161383139643233643761323338353838366132666330633037396638376136306131303236353962373738356135326263643630373335373965373765326639643339363231363931396431343632646664306465386461363735643362336338303330663036326630323536341a030102031aaf030aa4020a423033356531646533303438613632663966343738343430613232666437363535623830663061616339393762653936336231313961633534623362666465613362371a0361626322033132332a0364656632033435363a036768694a80013237383634636335323139613935316137613665353262386338646464663639383164303938646131363538643936323538633837306232633838646662636235313834316165613137326132386261666136613739373331313635353834363737303636303435633935396564306639393239363838643034646566633239524230333565316465333034386136326639663437383434306132326664373635356238306630616163393937626539363362313139616335346233626664656133623712800134363131376435623430393439386566326565353766306161633863393262316439383135323863656134373161323063363433396333343466623061623561333436326236383039396132666564373430353234313465303438636230663230303235626662663633373635363631336538646464316466643031316432311a03010203" 14 | ) 15 | 16 | func TestEncoder(t *testing.T) { 17 | private_key, _ := hex.DecodeString(PRIV_HEX) 18 | encoder := NewEncoder(private_key, TransactionParams{ 19 | FamilyName: "abc", 20 | FamilyVersion: "123", 21 | Inputs: []string{"def"}, 22 | }) 23 | 24 | txn1 := encoder.NewTransaction(data, TransactionParams{ 25 | Nonce: "123", 26 | Outputs: []string{"def"}, 27 | }) 28 | 29 | priv := signing.NewSecp256k1PrivateKey(private_key) 30 | pubstr := signing.NewSecp256k1Context().GetPublicKey(priv).AsHex() 31 | txn2 := encoder.NewTransaction(data, TransactionParams{ 32 | Nonce: "456", 33 | Outputs: []string{"ghi"}, 34 | BatcherPublicKey: pubstr, 35 | }) 36 | 37 | // Test serialization 38 | txns, err := ParseTransactions(SerializeTransactions([]*Transaction{txn1, txn2})) 39 | if err != nil { 40 | t.Error(err) 41 | } 42 | 43 | batch := encoder.NewBatch(txns) 44 | 45 | // Test serialization 46 | batches, err := ParseBatches(SerializeBatches([]*Batch{batch})) 47 | if err != nil { 48 | t.Error(err) 49 | } 50 | data := SerializeBatches(batches) 51 | datastr := hex.EncodeToString(data) 52 | 53 | expected := ENCDED 54 | 55 | if datastr != expected { 56 | t.Error("Did not correctly encode batch. Got", datastr) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/unit_seth.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ------------------------------------------------------------------------------ 15 | 16 | version: "2.1" 17 | 18 | services: 19 | 20 | unit-seth: 21 | build: 22 | context: .. 23 | dockerfile: ./cli/Dockerfile 24 | args: 25 | ISOLATION_ID: ${ISOLATION_ID} 26 | image: sawtooth-seth-cli-go:${ISOLATION_ID} 27 | working_dir: /project/sawtooth-seth/tests 28 | command: go test 29 | --------------------------------------------------------------------------------