├── .env ├── .github └── settings.yml ├── .gitignore ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── Dockerfile ├── Jenkinsfile ├── LICENSE ├── MAINTAINERS.md ├── README.md ├── SECURITY.md ├── VERSION ├── bin ├── authorize-cicd ├── get_version ├── intkey-tp-go ├── noop-tp-go ├── run_go_fmt ├── smallbank-tp-go └── xo-tp-go ├── c ├── c11_support.c ├── c11_support.h └── loader.c ├── ci ├── nightly │ ├── sawtooth-intkey-tp-go │ ├── sawtooth-smallbank-tp-go │ └── sawtooth-xo-tp-go ├── sawtooth-intkey-tp-go ├── sawtooth-smallbank-tp-go └── sawtooth-xo-tp-go ├── consensus ├── doc.go ├── engine.go ├── errors.go ├── iface.go ├── service.go └── types.go ├── docker-compose-installed.yaml ├── docker ├── compose │ ├── copy-debs.yaml │ ├── sawtooth-default-go.yaml │ └── sawtooth-smallbank-go.yaml ├── sawtooth-int-intkey-tp-go ├── sawtooth-int-noop-tp-go ├── sawtooth-int-smallbank-tp-go └── sawtooth-int-xo-tp-go ├── examples ├── devmode_consensus │ ├── engine.go │ ├── go.mod │ ├── go.sum │ └── main.go ├── intkey_go │ ├── Dockerfile-installed-bionic │ ├── intkey-tests.dockerfile │ ├── packaging │ │ ├── systemd │ │ │ ├── etc │ │ │ │ └── default │ │ │ │ │ └── sawtooth-intkey-tp-go │ │ │ └── lib │ │ │ │ └── systemd │ │ │ │ └── system │ │ │ │ └── sawtooth-intkey-tp-go.service │ │ └── ubuntu │ │ │ ├── changelog │ │ │ ├── control │ │ │ └── postinst │ ├── src │ │ ├── sawtooth_intkey │ │ │ ├── handler │ │ │ │ └── handler.go │ │ │ └── main.go │ │ └── sawtooth_intkey_client │ │ │ ├── constants.go │ │ │ ├── dec.go │ │ │ ├── inc.go │ │ │ ├── intkey_client.go │ │ │ ├── list.go │ │ │ ├── main.go │ │ │ ├── main_test.go │ │ │ ├── set.go │ │ │ └── show.go │ └── tests │ │ ├── test_intkey_smoke_go.yaml │ │ └── test_tp_intkey_go.yaml ├── noop_go │ ├── Dockerfile-installed-bionic │ ├── packaging │ │ ├── systemd │ │ │ ├── etc │ │ │ │ └── default │ │ │ │ │ └── sawtooth-noop-tp-go │ │ │ └── lib │ │ │ │ └── systemd │ │ │ │ └── system │ │ │ │ └── sawtooth-noop-tp-go.service │ │ └── ubuntu │ │ │ ├── changelog │ │ │ ├── control │ │ │ └── postinst │ └── src │ │ └── sawtooth_noop │ │ ├── handler │ │ └── handler.go │ │ └── main.go ├── smallbank │ ├── protos │ │ └── smallbank.proto │ └── smallbank_go │ │ ├── Dockerfile-installed-bionic │ │ ├── packaging │ │ ├── systemd │ │ │ ├── etc │ │ │ │ └── default │ │ │ │ │ └── sawtooth-smallbank-tp-go │ │ │ └── lib │ │ │ │ └── systemd │ │ │ │ └── system │ │ │ │ └── sawtooth-smallbank-tp-go.service │ │ └── ubuntu │ │ │ ├── changelog │ │ │ ├── control │ │ │ └── postinst │ │ └── src │ │ ├── protobuf │ │ └── smallbank_pb2 │ │ │ └── smallbank.pb.go │ │ └── sawtooth_smallbank │ │ ├── handler │ │ └── handler.go │ │ └── main.go └── xo_go │ ├── Dockerfile-installed-bionic │ ├── packaging │ ├── systemd │ │ ├── etc │ │ │ └── default │ │ │ │ └── sawtooth-xo-tp-go │ │ └── lib │ │ │ └── systemd │ │ │ └── system │ │ │ └── sawtooth-xo-tp-go.service │ └── ubuntu │ │ ├── changelog │ │ ├── control │ │ └── postinst │ ├── src │ └── sawtooth_xo │ │ ├── handler │ │ └── handler.go │ │ ├── main.go │ │ ├── xo_payload │ │ └── xo_payload.go │ │ └── xo_state │ │ └── xo_state.go │ ├── tests │ ├── test_tp_xo_go.yaml │ └── test_xo_smoke_go.yaml │ └── xo-tests.dockerfile ├── gen.go ├── gen.sh ├── go.mod ├── go.sum ├── logging └── logger.go ├── messaging └── connection.go ├── mocks └── mock_messaging │ └── connection.go ├── processor ├── context.go ├── errors.go ├── handler.go ├── processor.go └── worker.go ├── protobuf ├── authorization_pb2 │ └── authorization.pb.go ├── batch_pb2 │ └── batch.pb.go ├── block_info_pb2 │ └── block_info.pb.go ├── block_pb2 │ └── block.pb.go ├── client_batch_pb2 │ └── client_batch.pb.go ├── client_batch_submit_pb2 │ └── client_batch_submit.pb.go ├── client_block_pb2 │ └── client_block.pb.go ├── client_event_pb2 │ └── client_event.pb.go ├── client_list_control_pb2 │ └── client_list_control.pb.go ├── client_peer │ └── client_peers.pb.go ├── client_peers_pb2 │ └── client_peers.pb.go ├── client_receipt_pb2 │ └── client_receipt.pb.go ├── client_state_pb2 │ └── client_state.pb.go ├── client_status │ └── client_status.pb.go ├── client_status_pb2 │ └── client_status.pb.go ├── client_transaction_pb2 │ └── client_transaction.pb.go ├── consensus_pb2 │ └── consensus.pb.go ├── events_pb2 │ └── events.pb.go ├── genesis_pb2 │ └── genesis.pb.go ├── identity_pb2 │ └── identity.pb.go ├── merkle_pb2 │ └── merkle.pb.go ├── network_pb2 │ └── network.pb.go ├── processor_pb2 │ └── processor.pb.go ├── setting_pb2 │ └── setting.pb.go ├── state_context_pb2 │ └── state_context.pb.go ├── transaction_pb2 │ └── transaction.pb.go ├── transaction_receipt_pb2 │ └── transaction_receipt.pb.go ├── txn_receipt_pb2 │ └── transaction_receipt.pb.go └── validator_pb2 │ └── validator.pb.go ├── protogen ├── protos ├── authorization.proto ├── batch.proto ├── block.proto ├── block_info.proto ├── client_batch.proto ├── client_batch_submit.proto ├── client_block.proto ├── client_event.proto ├── client_list_control.proto ├── client_peers.proto ├── client_receipt.proto ├── client_state.proto ├── client_status.proto ├── client_transaction.proto ├── consensus.proto ├── events.proto ├── genesis.proto ├── identity.proto ├── merkle.proto ├── network.proto ├── processor.proto ├── setting.proto ├── state_context.proto ├── transaction.proto ├── transaction_receipt.proto └── validator.proto ├── signing ├── core.go ├── pem_loader.go └── secp256k1.go └── tests ├── integration-tests.dockerfile ├── secp256k1_test.go ├── state_test.go ├── test_systemd.sh └── test_systemd_services.yaml /.env: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | ISOLATION_ID=latest 16 | DISTRO=bionic 17 | -------------------------------------------------------------------------------- /.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-sdk-go 18 | homepage: https://wiki.hyperledger.org/display/sawtooth 19 | private: false 20 | has_issues: true 21 | has_projects: false 22 | has_wiki: false 23 | archived: true 24 | has_downloads: false 25 | default_branch: main 26 | allow_squash_merge: false 27 | allow_merge_commit: true 28 | allow_rebase_merge: true 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | # Exclude IDE and Editor files 17 | .project 18 | 19 | # Everything else 20 | mocks/ 21 | protos/output/ 22 | .vscode/ 23 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @agunde406 @cianx @dcmiddle @jsmitchell @peterschwarz @rberg2 @rbuysse @vaporos 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 | -------------------------------------------------------------------------------- /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 | # Description: 17 | # Builds an image to be used when developing in Go. The default CMD is to run 18 | # build_go. 19 | # 20 | # Build: 21 | # $ cd sawtooth-sdk-go/docker 22 | # $ docker build . -f sawtooth-build-go-protos -t sawtooth-build-go-protos 23 | # 24 | # Run: 25 | # $ cd sawtooth-sdk-go 26 | # $ docker run -v $(pwd):/project/sawtooth-sdk-go sawtooth-build-go-protos 27 | 28 | FROM ubuntu:bionic 29 | 30 | RUN apt-get update \ 31 | && apt-get install gnupg -y 32 | 33 | LABEL "install-type"="mounted" 34 | 35 | RUN echo "deb http://repo.sawtooth.me/ubuntu/ci bionic universe" >> /etc/apt/sources.list \ 36 | && echo 'deb http://ppa.launchpad.net/gophers/archive/ubuntu bionic main' >> /etc/apt/sources.list \ 37 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 38 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 39 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 308C15A29AD198E9 \ 40 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 308C15A29AD198E9) \ 41 | && apt-get update \ 42 | && apt-get install -y -q \ 43 | git \ 44 | libssl-dev \ 45 | libzmq3-dev \ 46 | openssl \ 47 | protobuf-compiler \ 48 | python3 \ 49 | python3-pip \ 50 | python3-pkg-resources \ 51 | wget \ 52 | pkg-config \ 53 | && apt-get clean \ 54 | && rm -rf /var/lib/apt/lists/* 55 | 56 | RUN wget https://go.dev/dl/go1.16.15.linux-amd64.tar.gz 57 | RUN tar -C /usr/local -xzf go1.16.15.linux-amd64.tar.gz 58 | 59 | RUN pip3 install grpcio grpcio-tools 60 | 61 | ENV GOPATH=/go:/project/:/go/src/github.com/hyperledger/sawtooth-sdk-go:/go/src/github.com/hyperledger/sawtooth-sdk-go/examples/smallbank/smallbank_go/:/go/src/github.com/hyperledger/sawtooth-sdk-go/protobuf 62 | 63 | ENV PATH=$PATH:/go/bin:/usr/local/go/bin 64 | 65 | RUN mkdir /go 66 | 67 | COPY . /go/src/github.com/hyperledger/sawtooth-sdk-go 68 | 69 | WORKDIR /go/src/github.com/hyperledger/sawtooth-sdk-go/ 70 | 71 | RUN go mod download 72 | 73 | CMD go generate 74 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | ## Maintainers 2 | 3 | ### Active Maintainers 4 | | Name | GitHub | 5 | | --- | --- | 6 | | Andi Gunderson | agunde406 | 7 | | Cian Montgomery | cianx | 8 | | Dan Middleton | dcmiddle | 9 | | James Mitchell | jsmitchell | 10 | | Peter Schwarz | peterschwarz | 11 | | Richard Berg | rberg2 | 12 | | Ryan Beck-Buysse | rbuysse | 13 | | Shawn Amundson | vaporos | 14 | 15 | ### Retired Maintainers 16 | | Name | GitHub | 17 | | --- | --- | 18 | | Adam Ludvik | aludvik | 19 | | Anne Chenette | chenette | 20 | | Boyd Johnson | boydjohnson | 21 | | Darian Plumb | dplumb94 | 22 | | Jamie Jason | jjason | 23 | | Nick Drozd | nick-drozd | 24 | | Zac Delventhal | delventhalz | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hyperledger Sawtooth 2 | 3 | This project has moved (see below). 4 | 5 | Hyperledger Sawtooth was a project to provide an enterprise solution for 6 | building, deploying, and running distributed ledgers (also called blockchains). 7 | 8 | # Project Status 9 | 10 | This Hyperledger project, Hyperledger Sawtooth, has been archived and is no 11 | longer active within Hyperledger. 12 | 13 | Sawtooth is now maintained by the Splinter community. For more information, 14 | visit: https://github.com/splintercommunity/sawtooth-core/ 15 | 16 | # License 17 | 18 | Hyperledger Sawtooth software is licensed under the [Apache License Version 2.0](LICENSE) software license. 19 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Hyperledger Security Policy 2 | 3 | ## Reporting a Security Bug 4 | 5 | If you think you have discovered a security issue in any of the Hyperledger 6 | projects, we'd love to hear from you. We will take all security bugs 7 | seriously and if confirmed upon investigation we will patch it within a 8 | reasonable amount of time and release a public security bulletin discussing 9 | the impact and credit the discoverer. 10 | 11 | There are two ways to report a security bug. The easiest is to email a 12 | description of the flaw and any related information (e.g. reproduction 13 | steps, version) to 14 | [security at hyperledger dot org](mailto:security@hyperledger.org). 15 | 16 | The other way is to file a confidential security bug in our 17 | [JIRA bug tracking system](https://jira.hyperledger.org). 18 | Be sure to set the “Security Level” to “Security issue”. 19 | 20 | The process by which the Hyperledger Security Team handles security bugs 21 | is documented further in our 22 | [Defect Response](https://wiki.hyperledger.org/display/HYP/Defect+Response) 23 | page on our [wiki](https://wiki.hyperledger.org). 24 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.1.5 2 | -------------------------------------------------------------------------------- /bin/authorize-cicd: -------------------------------------------------------------------------------- 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 | if [[ -z $1 || -z $2 ]] 19 | then 20 | echo "USAGE: $0 [user] [authlist]" 21 | exit 1 22 | fi 23 | 24 | authlist=$(cat $2 | grep user | sed 's#.*: \(.*$\)#\1#') 25 | for user in $authlist 26 | do 27 | if [[ $user == $1 ]] 28 | then 29 | echo "SUCCESS: User '$1' authorized" 30 | exit 0 31 | fi 32 | done 33 | 34 | echo "FAILED: User '$1' not authorized." 35 | exit 1 36 | -------------------------------------------------------------------------------- /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/intkey-tp-go: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env 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 | top_dir=$(cd $(dirname $(dirname $0)) && pwd) 19 | bin=$top_dir/sdk/examples/intkey_go/bin/intkey-tp-go 20 | 21 | if [ -e $bin ] 22 | then 23 | $bin $* 24 | else 25 | echo "Please build IntKey Go first with 'build_all -l go' or 'build_go'" 26 | fi 27 | -------------------------------------------------------------------------------- /bin/noop-tp-go: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env 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 | top_dir=$(cd $(dirname $(dirname $0)) && pwd) 19 | bin=$top_dir/sdk/examples/noop_go/bin/noop-tp-go 20 | 21 | if [ -e $bin ] 22 | then 23 | $bin $* 24 | else 25 | echo "Please build Noop Go first with 'build_all -l go' or 'build_go'" 26 | fi 27 | -------------------------------------------------------------------------------- /bin/run_go_fmt: -------------------------------------------------------------------------------- 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 | top_dir=$(pwd) 19 | 20 | cd $top_dir 21 | 22 | dirs=" 23 | $top_dir/logging 24 | $top_dir/messaging 25 | $top_dir/processor 26 | $top_dir/signing 27 | $top_dir/tests 28 | $top_dir/examples/intkey_go/src/sawtooth_intkey 29 | $top_dir/examples/intkey_go/src/sawtooth_intkey/handler 30 | $top_dir/examples/intkey_go/src/sawtooth_intkey_client 31 | $top_dir/examples/noop_go/src/sawtooth_noop 32 | $top_dir/examples/noop_go/src/sawtooth_noop/handler 33 | $top_dir/examples/smallbank/smallbank_go/src/sawtooth_smallbank 34 | $top_dir/examples/smallbank/smallbank_go/src/sawtooth_smallbank/handler 35 | $top_dir/examples/xo_go/src/sawtooth_xo 36 | $top_dir/examples/xo_go/src/sawtooth_xo/handler 37 | " 38 | 39 | exitcode=0 40 | for dir in $dirs 41 | do 42 | if [ -z $1 ] 43 | then 44 | changed=$(gofmt -l $(ls -1 $dir/*.go)) 45 | if [[ ! -z $changed ]] 46 | then 47 | echo "Incorrect formatting: $dir" 48 | exitcode=1 49 | fi 50 | else 51 | gofmt -w -l $(ls -1 $dir/*.go) 52 | fi 53 | done 54 | if [ $exitcode -ne 0 ] 55 | then 56 | echo "Do 'run_go_fmt fix' to fix" 57 | fi 58 | exit $exitcode 59 | -------------------------------------------------------------------------------- /bin/smallbank-tp-go: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env 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 | top_dir=$(cd $(dirname $(dirname $0)) && pwd) 19 | bin=$top_dir/families/smallbank/smallbank_go/bin/smallbank-tp-go 20 | 21 | if [ -e $bin ] 22 | then 23 | $bin $* 24 | else 25 | echo "Please build Smallbank Go first with 'build_all -l go' or 'build_go'" 26 | fi 27 | -------------------------------------------------------------------------------- /bin/xo-tp-go: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env 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 | top_dir=$(cd $(dirname $(dirname $0)) && pwd) 19 | bin=$top_dir/sdk/examples/xo_go/bin/xo-tp-go 20 | 21 | if [ -e $bin ] 22 | then 23 | $bin $* 24 | else 25 | echo "Please build Xo Go first with 'build_all -l go' or 'build_go'" 26 | fi 27 | -------------------------------------------------------------------------------- /c/c11_support.c: -------------------------------------------------------------------------------- 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 19 | #include "c11_support.h" 20 | 21 | #ifndef __STDC_LIB_EXT1__ 22 | int strncpy_s(char *dest, size_t sizeInBytes, const char *src, size_t count) 23 | { 24 | if (count == 0 && dest == NULL && sizeInBytes == 0) { 25 | return 0; 26 | } 27 | 28 | if (dest == NULL || sizeInBytes <= 0) { 29 | return EINVAL; 30 | } 31 | 32 | if (count == 0) { 33 | *dest = 0; 34 | return 0; 35 | } 36 | 37 | if (src == NULL) { 38 | *dest = 0; 39 | return EINVAL; 40 | } 41 | 42 | char *p = dest; 43 | size_t availableSize = sizeInBytes; 44 | 45 | if (count == ((size_t) - 1)) { 46 | while ((*p++ = *src++) != 0 && --availableSize > 0); 47 | } else { 48 | while ((*p++ = *src++) != 0 && --availableSize > 0 && --count > 0); 49 | if (count == 0) { 50 | p = NULL; 51 | } 52 | } 53 | 54 | if (availableSize == 0) 55 | { 56 | if (count == ((size_t) - 1)) 57 | { 58 | dest[sizeInBytes - 1] = 0; 59 | return STRUNCATE; 60 | } 61 | *dest = 0; 62 | return ERANGE; 63 | } 64 | return 0; 65 | } 66 | 67 | #endif // #ifdef __STDC_LIB_EXT1__ 68 | -------------------------------------------------------------------------------- /c/c11_support.h: -------------------------------------------------------------------------------- 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 | #ifndef C11_SUPPORT_H 19 | #define C11_SUPPORT_H 20 | 21 | #include 22 | // If the compiler has been built with optional extensions, then we can have 23 | // some of the missing functions made available by defining the appropriate 24 | // preprocessor define before including string.h 25 | #ifdef __STDC_LIB_EXT1__ 26 | #define __STDC_WANT_LIB_EXT1__ 1 27 | #else 28 | int strncpy_s(char *dest, size_t sizeInBytes, 29 | const char *src, size_t count); 30 | #endif // #ifdef __STDC_LIB_EXT1__ 31 | 32 | #include 33 | 34 | #ifndef STRUNCATE 35 | #define STRUNCATE 80 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /c/loader.c: -------------------------------------------------------------------------------- 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 "c11_support.h" 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | // Extract the private and public keys from the PEM file, using the supplied 30 | // password to decrypt the file if encrypted. priv_key and pub_key must point to 31 | // an array o at least 65 and 131 character respectively. 32 | int load_pem_key(char *pemstr, size_t pemstr_len, char *password, 33 | char *out_priv_key, char *out_pub_key) { 34 | 35 | BIO *in = NULL; 36 | 37 | BN_CTX *ctx = NULL; 38 | const EC_GROUP *group; 39 | EC_KEY *eckey = NULL; 40 | const EC_POINT *pub_key_point = NULL; 41 | const BIGNUM *priv_key = NULL, *pub_key = NULL; 42 | 43 | char *priv_key_hex = NULL; 44 | char *pub_key_hex = NULL; 45 | 46 | in = BIO_new_mem_buf(pemstr, (int)pemstr_len); 47 | 48 | // Read key from stream, decrypting with password if not NULL 49 | if (password != NULL && strcmp("", password) != 0) { 50 | // Initialize ciphers 51 | ERR_load_crypto_strings (); 52 | OpenSSL_add_all_algorithms (); 53 | 54 | eckey = PEM_read_bio_ECPrivateKey(in, NULL, NULL, password); 55 | if (eckey == NULL) { 56 | return -1; // Failed to decrypt or decode private key 57 | } 58 | } else { 59 | if ((eckey = PEM_read_bio_ECPrivateKey(in, NULL, NULL, NULL)) == NULL) { 60 | return -1; // Failed to decode private key 61 | } 62 | } 63 | BIO_free(in); 64 | 65 | // Deconstruct key into big numbers 66 | if ((ctx = BN_CTX_new()) == NULL) { 67 | return -2; // Failed to create new big number context 68 | } 69 | if ((group = EC_KEY_get0_group(eckey)) == NULL) { 70 | return -3; // Failed to load group 71 | } 72 | if ((priv_key = EC_KEY_get0_private_key(eckey)) == NULL) { 73 | return -4; // Failed to load private key 74 | } 75 | if ((pub_key_point = EC_KEY_get0_public_key(eckey)) == NULL) { 76 | return -5; // Failed to load public key point 77 | } 78 | pub_key = EC_POINT_point2bn(group, pub_key_point, EC_KEY_get_conv_form(eckey), NULL, ctx); 79 | if (pub_key == NULL) { 80 | return -6; // Failed to construct public key from point 81 | } 82 | 83 | priv_key_hex = BN_bn2hex(priv_key); 84 | pub_key_hex = BN_bn2hex(pub_key); 85 | strncpy_s(out_priv_key, 64 + 1, priv_key_hex, 64 + 1); 86 | strncpy_s(out_pub_key, 130 + 1, pub_key_hex, 130 + 1); 87 | OPENSSL_free(priv_key_hex); 88 | OPENSSL_free(pub_key_hex); 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /ci/nightly/sawtooth-intkey-tp-go: -------------------------------------------------------------------------------- 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 | 16 | # Description: 17 | # Builds an image with the Sawtooth TP Intkey package installed from 18 | # the Sawtooth Package Repository. 19 | # 20 | # Build: 21 | # $ cd sawtooth-sdk-go/ci/nightly 22 | # $ docker build . -f sawtooth-intkey-tp-go -t sawtooth-intkey-tp-go 23 | # 24 | # Run: 25 | # $ docker run sawtooth-intkey-tp-go 26 | 27 | FROM ubuntu:bionic 28 | 29 | RUN apt-get update \ 30 | && apt-get install gnupg -y 31 | 32 | LABEL "install-type"="repo" 33 | 34 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/nightly bionic universe" >> /etc/apt/sources.list \ 35 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 36 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 37 | && apt-get update \ 38 | && apt-get install -y -q \ 39 | sawtooth-intkey-tp-go \ 40 | && apt-get clean \ 41 | && rm -rf /var/lib/apt/lists/* 42 | 43 | CMD ["intkey-tp-go", "-vv"] 44 | -------------------------------------------------------------------------------- /ci/nightly/sawtooth-smallbank-tp-go: -------------------------------------------------------------------------------- 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 | 16 | # Description: 17 | # Builds an image with the Sawtooth TP Smallbank package installed from 18 | # the Sawtooth Package Repository. 19 | # 20 | # Build: 21 | # $ cd sawtooth-sdk-go/ci/nightly 22 | # $ docker build . -f sawtooth-smallbank-tp-go -t sawtooth-smallbank-tp-go 23 | # 24 | # Run: 25 | # $ docker run sawtooth-smallbank-tp-go 26 | 27 | FROM ubuntu:bionic 28 | 29 | RUN apt-get update \ 30 | && apt-get install gnupg -y 31 | 32 | LABEL "install-type"="repo" 33 | 34 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/nightly bionic universe" >> /etc/apt/sources.list \ 35 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 36 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \ 37 | && apt-get update \ 38 | && apt-get install -y -q \ 39 | sawtooth-smallbank-tp-go \ 40 | && apt-get clean \ 41 | && rm -rf /var/lib/apt/lists/* 42 | 43 | CMD ["smallbank-tp-go", "-vv"] 44 | -------------------------------------------------------------------------------- /ci/nightly/sawtooth-xo-tp-go: -------------------------------------------------------------------------------- 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 | 16 | # Description: 17 | # Builds an image with the Sawtooth TP xo package installed from 18 | # the Sawtooth Package Repository. 19 | # 20 | # Build: 21 | # $ cd sawtooth-sdk-go/ci/nightly 22 | # $ docker build . -f sawtooth-xo-tp-go -t sawtooth-xo-tp-go 23 | # 24 | # Run: 25 | # $ docker run sawtooth-xo-tp-go 26 | 27 | FROM ubuntu:bionic 28 | 29 | RUN apt-get update \ 30 | && apt-get install gnupg -y 31 | 32 | LABEL "install-type"="repo" 33 | 34 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/nightly bionic universe" >> /etc/apt/sources.list \ 35 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 36 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 37 | && apt-get update \ 38 | && apt-get install -y -q \ 39 | sawtooth-xo-tp-go \ 40 | && apt-get clean \ 41 | && rm -rf /var/lib/apt/lists/* 42 | 43 | CMD ["xo-tp-go", "-vv"] 44 | -------------------------------------------------------------------------------- /ci/sawtooth-intkey-tp-go: -------------------------------------------------------------------------------- 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 | # Description: 17 | # Builds an image with the Sawtooth TP Intkey package installed from 18 | # the Sawtooth Package Repository. 19 | # 20 | # Build: 21 | # $ cd sawtooth-core/ci 22 | # $ docker build . -f sawtooth-intkey-tp-go -t sawtooth-intkey-tp-go 23 | # 24 | # Run: 25 | # $ cd sawtooth-core 26 | # $ docker run sawtooth-intkey-tp-go 27 | 28 | FROM ubuntu:bionic 29 | 30 | LABEL "install-type"="repo" 31 | 32 | RUN apt-get update \ 33 | && apt-get install gnupg -y 34 | 35 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/chime/stable bionic universe" >> /etc/apt/sources.list \ 36 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 37 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 38 | && apt-get update \ 39 | && apt-get install -y -q \ 40 | sawtooth-intkey-tp-go \ 41 | && apt-get clean \ 42 | && rm -rf /var/lib/apt/lists/* 43 | 44 | CMD ["intkey-tp-go", "-vv"] 45 | -------------------------------------------------------------------------------- /ci/sawtooth-smallbank-tp-go: -------------------------------------------------------------------------------- 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 | # Description: 17 | # Builds an image with the Sawtooth TP Smallbank package installed from 18 | # the Sawtooth Package Repository. 19 | # 20 | # Build: 21 | # $ cd sawtooth-core/docker 22 | # $ docker build . -f sawtooth-smallbank-tp-go -t sawtooth-smallbank-tp-go 23 | # 24 | # Run: 25 | # $ cd sawtooth-core 26 | # $ docker run sawtooth-smallbank-tp-go 27 | 28 | FROM ubuntu:bionic 29 | 30 | LABEL "install-type"="repo" 31 | 32 | RUN apt-get update \ 33 | && apt-get install gnupg -y 34 | 35 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/chime/stable bionic universe" >> /etc/apt/sources.list \ 36 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 37 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 38 | && apt-get update \ 39 | && apt-get install -y -q \ 40 | sawtooth-smallbank-tp-go \ 41 | && apt-get clean \ 42 | && rm -rf /var/lib/apt/lists/* 43 | 44 | CMD ["smallbank-tp-go", "-vv"] 45 | -------------------------------------------------------------------------------- /ci/sawtooth-xo-tp-go: -------------------------------------------------------------------------------- 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 | # Description: 17 | # Builds an image with the Sawtooth TP xo package installed from 18 | # the Sawtooth Package Repository. 19 | # 20 | # Build: 21 | # $ cd sawtooth-core/docker 22 | # $ docker build . -f sawtooth-xo-tp-go -t sawtooth-xo-tp-go 23 | # 24 | # Run: 25 | # $ cd sawtooth-core 26 | # $ docker run sawtooth-xo-tp-go 27 | 28 | FROM ubuntu:bionic 29 | 30 | LABEL "install-type"="repo" 31 | 32 | RUN apt-get update \ 33 | && apt-get install gnupg -y 34 | 35 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/chime/stable bionic universe" >> /etc/apt/sources.list \ 36 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 37 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 38 | && apt-get update \ 39 | && apt-get install -y -q \ 40 | sawtooth-xo-tp-go \ 41 | && apt-get clean \ 42 | && rm -rf /var/lib/apt/lists/* 43 | 44 | CMD ["xo-tp-go", "-vv"] 45 | -------------------------------------------------------------------------------- /consensus/doc.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2022 Grid 7, LLC (DBA Taekion) 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 consensus provides a facility for implementing a Sawtooth pluggable consensus engine. 19 | package consensus 20 | -------------------------------------------------------------------------------- /consensus/errors.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2022 Grid 7, LLC (DBA Taekion) 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 consensus 19 | 20 | import "fmt" 21 | 22 | type EncodingError struct { 23 | Msg string 24 | } 25 | 26 | func (self *EncodingError) Error() string { 27 | return fmt.Sprintf("EncodingError: %s", self.Msg) 28 | } 29 | 30 | // IsEncodingError returns whether the error is an EncodingError. 31 | func IsEncodingError(err error) bool { 32 | _, ok := err.(*EncodingError) 33 | return ok 34 | } 35 | 36 | type SendError struct { 37 | Msg string 38 | } 39 | 40 | func (self *SendError) Error() string { 41 | return fmt.Sprintf("SendError: %s", self.Msg) 42 | } 43 | 44 | // IsSendError returns whether the error is a SendError. 45 | func IsSendError(err error) bool { 46 | _, ok := err.(*SendError) 47 | return ok 48 | } 49 | 50 | type ReceiveError struct { 51 | Msg string 52 | } 53 | 54 | func (self *ReceiveError) Error() string { 55 | return fmt.Sprintf("ReceiveError: %s", self.Msg) 56 | } 57 | 58 | // IsReceiveError returns whether the error is a ReceiveError. 59 | func IsReceiveError(err error) bool { 60 | _, ok := err.(*ReceiveError) 61 | return ok 62 | } 63 | 64 | type InvalidStateError struct { 65 | Msg string 66 | } 67 | 68 | func (self *InvalidStateError) Error() string { 69 | return fmt.Sprintf("InvalidState: %s", self.Msg) 70 | } 71 | 72 | // IsInvalidStateError returns whether the error is a InvalidStateError. 73 | func IsInvalidStateError(err error) bool { 74 | _, ok := err.(*InvalidStateError) 75 | return ok 76 | } 77 | 78 | type UnknownBlockError struct { 79 | Msg string 80 | } 81 | 82 | func (self *UnknownBlockError) Error() string { 83 | return fmt.Sprintf("UnknownBlock: %s", self.Msg) 84 | } 85 | 86 | // IsUnknownBlockError returns whether the error is a UnknownBlockError. 87 | func IsUnknownBlockError(err error) bool { 88 | _, ok := err.(*UnknownBlockError) 89 | return ok 90 | } 91 | 92 | type UnknownPeerError struct { 93 | Msg string 94 | } 95 | 96 | func (self *UnknownPeerError) Error() string { 97 | return fmt.Sprintf("UnknownPeer: %s", self.Msg) 98 | } 99 | 100 | // IsUnknownPeerError returns whether the error is a UnknownPeerError. 101 | func IsUnknownPeerError(err error) bool { 102 | _, ok := err.(*UnknownPeerError) 103 | return ok 104 | } 105 | 106 | type NoChainHeadError struct{} 107 | 108 | func (self *NoChainHeadError) Error() string { 109 | return fmt.Sprint("NoChainHead") 110 | } 111 | 112 | // IsNoChainHeadError returns whether the error is a NoChainHeadError. 113 | func IsNoChainHeadError(err error) bool { 114 | _, ok := err.(*NoChainHeadError) 115 | return ok 116 | } 117 | 118 | type BlockNotReadyError struct{} 119 | 120 | func (self *BlockNotReadyError) Error() string { 121 | return fmt.Sprint("BlockNotReady") 122 | } 123 | 124 | // IsBlockNotReadyError returns whether the error is a BlockNotReadyError. 125 | func IsBlockNotReadyError(err error) bool { 126 | _, ok := err.(*BlockNotReadyError) 127 | return ok 128 | } 129 | -------------------------------------------------------------------------------- /consensus/iface.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2022 Grid 7, LLC (DBA Taekion) 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 consensus 19 | 20 | // ConsensusService provides methods that allow the consensus engine to issue commands and requests 21 | // back to the validator. 22 | type ConsensusService interface { 23 | // -- P2P -- 24 | 25 | // SendTo sends a consensus message to a specific, connected peer. 26 | SendTo(peer PeerId, messageType string, payload []byte) error 27 | // Broadcast broadcasts a message to all connected peers. 28 | Broadcast(messageType string, payload []byte) error 29 | 30 | // -- Block Creation -- 31 | 32 | // InitializeBlock initializes a new block built on the block with the given previous id and 33 | // begins adding batches to it. If no previous id is specified, the current 34 | // head will be used. 35 | InitializeBlock(previousId BlockId) error 36 | // SummarizeBlock stops adding batches to the current block and returns a summary of its 37 | // contents. 38 | SummarizeBlock() ([]byte, error) 39 | // FinalizeBlock inserts the given consensus data into the block and signs it. If this call is successful, the 40 | // consensus engine will receive the block afterwards. 41 | FinalizeBlock(data []byte) (BlockId, error) 42 | // CancelBlock stops adding batches to the current block and abandons it. 43 | CancelBlock() error 44 | 45 | // -- Block Directives -- 46 | 47 | // CheckBlocks updates the prioritization of blocks to check. 48 | CheckBlocks(blockIds []BlockId) error 49 | // CommitBlock updates the block that should be committed. 50 | CommitBlock(blockId BlockId) error 51 | // IgnoreBlock signals that this block is no longer being committed. 52 | IgnoreBlock(blockId BlockId) error 53 | // FailBlock marks this block as invalid from the perspective of consensus. 54 | FailBlock(blockId BlockId) error 55 | 56 | // -- Queries -- 57 | 58 | // GetBlocks retrieves consensus-related information about blocks. 59 | GetBlocks(blockIds []BlockId) (map[BlockId]Block, error) 60 | // GetChainHead gets the chain head block. 61 | GetChainHead() (Block, error) 62 | // GetSettings reads the value of settings as of the given block. 63 | GetSettings(blockId BlockId, keys []string) (map[string]string, error) 64 | // GetState reads values in state as of the given block. 65 | GetState(blockId BlockId, addresses []string) (map[string][]byte, error) 66 | } 67 | 68 | // ConsensusEngineImpl must be implemented by any ConsensusEngine implementation. 69 | type ConsensusEngineImpl interface { 70 | // Name gets the name of the engine, typically the algorithm being implemented. 71 | Name() string 72 | 73 | // Version gets the version of this engine. 74 | Version() string 75 | 76 | // Start is called after the engine is initialized, when a connection to the validator has been 77 | // established. Requests to the validator are sent via calls to the interface methods on service. 78 | // Updates from the validator are received via updateChan. 79 | Start(startupState StartupState, service ConsensusService, updateChan chan ConsensusUpdate) error 80 | } 81 | -------------------------------------------------------------------------------- /docker-compose-installed.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | smallbank-tp-go: 20 | build: 21 | context: . 22 | dockerfile: examples/smallbank/smallbank_go/Dockerfile-installed-${DISTRO} 23 | args: 24 | - http_proxy 25 | - https_proxy 26 | - no_proxy 27 | image: sawtooth-smallbank-tp-go:${ISOLATION_ID} 28 | container_name: sawtooth-smallbank-tp-go-default 29 | 30 | sawtooth-intkey-tp-go: 31 | build: 32 | context: . 33 | dockerfile: examples/intkey_go/Dockerfile-installed-${DISTRO} 34 | args: 35 | - http_proxy 36 | - https_proxy 37 | - no_proxy 38 | image: sawtooth-intkey-tp-go:${ISOLATION_ID} 39 | container_name: sawtooth-intkey-tp-go-default 40 | 41 | sawtooth-noop-tp-go: 42 | build: 43 | context: . 44 | dockerfile: examples/noop_go/Dockerfile-installed-${DISTRO} 45 | args: 46 | - http_proxy 47 | - https_proxy 48 | - no_proxy 49 | image: sawtooth-noop-tp-go:${ISOLATION_ID} 50 | container_name: sawtooth-noop-tp-go-default 51 | 52 | sawtooth-xo-tp-go: 53 | build: 54 | context: . 55 | dockerfile: examples/xo_go/Dockerfile-installed-${DISTRO} 56 | args: 57 | - http_proxy 58 | - https_proxy 59 | - no_proxy 60 | image: sawtooth-xo-tp-go:${ISOLATION_ID} 61 | container_name: sawtooth-xo-tp-go-default 62 | -------------------------------------------------------------------------------- /docker/compose/copy-debs.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | smallbank-tp-go: 20 | image: sawtooth-smallbank-tp-go:${ISOLATION_ID} 21 | volumes: 22 | - ../../build/debs:/build/debs 23 | command: | 24 | bash -c " 25 | cp /tmp/*.deb /build/debs 26 | " 27 | 28 | sawtooth-intkey-tp-go: 29 | image: sawtooth-intkey-tp-go:${ISOLATION_ID} 30 | volumes: 31 | - ../../build/debs:/build/debs 32 | command: | 33 | bash -c " 34 | cp /tmp/*.deb /build/debs 35 | " 36 | 37 | sawtooth-noop-tp-go: 38 | image: sawtooth-noop-tp-go:${ISOLATION_ID} 39 | volumes: 40 | - ../../build/debs:/build/debs 41 | command: | 42 | bash -c " 43 | cp /tmp/*.deb /build/debs 44 | " 45 | 46 | sawtooth-xo-tp-go: 47 | image: sawtooth-xo-tp-go:${ISOLATION_ID} 48 | volumes: 49 | - ../../build/debs:/build/debs 50 | command: | 51 | bash -c " 52 | cp /tmp/*.deb /build/debs 53 | " 54 | -------------------------------------------------------------------------------- /docker/compose/sawtooth-default-go.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 | settings-tp: 21 | image: hyperledger/sawtooth-settings-tp:1.0 22 | container_name: sawtooth-settings-tp-default 23 | depends_on: 24 | - validator 25 | entrypoint: settings-tp -vv -C tcp://validator:4004 26 | 27 | intkey-tp-go: 28 | image: hyperledger/sawtooth-intkey-tp-go:1.0 29 | container_name: sawtooth-intkey-tp-go-default 30 | depends_on: 31 | - validator 32 | entrypoint: intkey-tp-go -vv -C tcp://validator:4004 33 | 34 | xo-tp-go: 35 | image: hyperledger/sawtooth-xo-tp-go:1.0 36 | container_name: sawtooth-xo-tp-go-default 37 | depends_on: 38 | - validator 39 | entrypoint: xo-tp-go -vv -C tcp://validator:4004 40 | 41 | validator: 42 | image: hyperledger/sawtooth-validator:1.0 43 | container_name: sawtooth-validator-default 44 | expose: 45 | - 4004 46 | ports: 47 | - "4004:4004" 48 | # start the validator with an empty genesis batch 49 | entrypoint: "bash -c \"\ 50 | sawadm keygen && \ 51 | sawtooth keygen my_key && \ 52 | sawset genesis -k /root/.sawtooth/keys/my_key.priv && \ 53 | sawadm genesis config-genesis.batch && \ 54 | sawtooth-validator -vv \ 55 | --endpoint tcp://validator:8800 \ 56 | --bind component:tcp://eth0:4004 \ 57 | --bind network:tcp://eth0:8800 \ 58 | \"" 59 | 60 | rest-api: 61 | image: hyperledger/sawtooth-rest-api:1.0 62 | container_name: sawtooth-rest-api-default 63 | expose: 64 | - 8008 65 | ports: 66 | - "8008:8008" 67 | depends_on: 68 | - validator 69 | entrypoint: sawtooth-rest-api -C tcp://validator:4004 --bind rest-api:8008 70 | 71 | shell: 72 | image: hyperledger/sawtooth-shell:1.0 73 | container_name: sawtooth-shell-default 74 | depends_on: 75 | - rest-api 76 | entrypoint: "bash -c \"\ 77 | sawtooth keygen && \ 78 | tail -f /dev/null \ 79 | \"" 80 | -------------------------------------------------------------------------------- /docker/compose/sawtooth-smallbank-go.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 | settings-tp: 21 | image: hyperledger/sawtooth-settings-tp:1.0 22 | container_name: sawtooth-settings-tp-default 23 | depends_on: 24 | - validator 25 | entrypoint: settings-tp -vv -C tcp://validator:4004 26 | 27 | smallbank-tp-go: 28 | image: hyperledger/sawtooth-smallbank-tp-go:1.0 29 | container_name: sawtooth-smallbank-tp-go-default 30 | depends_on: 31 | - validator 32 | entrypoint: smallbank-tp-go -vv tcp://validator:4004 33 | 34 | validator: 35 | image: hyperledger/sawtooth-validator:1.0 36 | container_name: sawtooth-validator-default 37 | expose: 38 | - 4004 39 | ports: 40 | - "4004:4004" 41 | # start the validator with an empty genesis batch 42 | entrypoint: "bash -c \"\ 43 | sawadm keygen && \ 44 | sawtooth keygen my_key && \ 45 | sawset genesis -k /root/.sawtooth/keys/my_key.priv && \ 46 | sawadm genesis config-genesis.batch && \ 47 | sawtooth-validator -vv \ 48 | --endpoint tcp://validator:8800 \ 49 | --bind component:tcp://eth0:4004 \ 50 | --bind network:tcp://eth0:8800 \ 51 | \"" 52 | 53 | rest-api: 54 | image: hyperledger/sawtooth-rest-api:1.0 55 | container_name: sawtooth-rest-api-default 56 | expose: 57 | - 8008 58 | ports: 59 | - "8008:8008" 60 | depends_on: 61 | - validator 62 | entrypoint: sawtooth-rest-api -C tcp://validator:4004 --bind rest-api:8008 63 | 64 | shell: 65 | image: hyperledger/sawtooth-shell:1.0 66 | container_name: sawtooth-shell-default 67 | depends_on: 68 | - rest-api 69 | entrypoint: "bash -c \"\ 70 | sawtooth keygen && \ 71 | tail -f /dev/null \ 72 | \"" 73 | -------------------------------------------------------------------------------- /docker/sawtooth-int-intkey-tp-go: -------------------------------------------------------------------------------- 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 | # Description: 17 | # Builds an image with Sawtooth TP Intkey Go installed. 18 | # 19 | # Build: 20 | # This image should be built using `build_all installed`. 21 | # 22 | # Run: 23 | # $ docker run sawtooth-intkey-tp-go 24 | 25 | FROM ubuntu:bionic 26 | 27 | RUN apt-get update \ 28 | && apt-get install gnupg -y 29 | 30 | LABEL "install-type"="local-debs" 31 | 32 | RUN apt-get update \ 33 | && apt-get install -y -q \ 34 | dpkg-dev \ 35 | && apt-get clean \ 36 | && rm -rf /var/lib/apt/lists/* \ 37 | && mkdir /debs 38 | 39 | COPY sawtooth-intkey-tp-go*.deb /debs/ 40 | 41 | RUN cd /debs \ 42 | && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz \ 43 | && echo "deb file:/debs ./" >> /etc/apt/sources.list \ 44 | && echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/ci bionic universe" >> /etc/apt/sources.list \ 45 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 46 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 47 | && apt-get update 48 | 49 | RUN apt-get update \ 50 | && apt-get install -y -q --allow-unauthenticated \ 51 | libssl-dev \ 52 | libzmq3-dev \ 53 | sawtooth-intkey-tp-go \ 54 | && apt-get clean \ 55 | && rm -rf /var/lib/apt/lists/* 56 | 57 | EXPOSE 4004/tcp 58 | 59 | CMD ["intkey-tp-go", "-C", "tcp://validator:4004"] 60 | -------------------------------------------------------------------------------- /docker/sawtooth-int-noop-tp-go: -------------------------------------------------------------------------------- 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 | # Description: 17 | # Builds an image with Sawtooth TP Noop Go installed. 18 | # 19 | # Build: 20 | # This image should be built using `build_all installed`. 21 | # 22 | # Run: 23 | # $ docker run sawtooth-noop-tp-go 24 | 25 | FROM ubuntu:bionic 26 | 27 | LABEL "install-type"="copied-bin" 28 | 29 | RUN apt-get update \ 30 | && apt-get install -y -q \ 31 | libssl-dev \ 32 | libzmq3-dev \ 33 | && apt-get clean \ 34 | && rm -rf /var/lib/apt/lists/* 35 | 36 | COPY noop-tp-go /usr/bin/noop-tp-go 37 | 38 | EXPOSE 4004/tcp 39 | 40 | CMD ["noop-tp-go", "-C", "tcp://validator:4004"] 41 | -------------------------------------------------------------------------------- /docker/sawtooth-int-smallbank-tp-go: -------------------------------------------------------------------------------- 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 | # Description: 17 | # Builds an image with Sawtooth TP Smallbank Go installed. 18 | # 19 | # Build: 20 | # This image should be built using `build_all installed`. 21 | # 22 | # Run: 23 | # $ docker run sawtooth-smallbank-tp-go 24 | 25 | FROM ubuntu:bionic 26 | 27 | RUN apt-get update \ 28 | && apt-get install gnupg -y 29 | 30 | LABEL "install-type"="local-debs" 31 | 32 | RUN apt-get update \ 33 | && apt-get install -y -q \ 34 | dpkg-dev \ 35 | && apt-get clean \ 36 | && rm -rf /var/lib/apt/lists/* \ 37 | && mkdir /debs 38 | 39 | COPY sawtooth-smallbank-tp-go*.deb /debs/ 40 | 41 | RUN cd /debs \ 42 | && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz \ 43 | && echo "deb file:/debs ./" >> /etc/apt/sources.list \ 44 | && echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/ci bionic universe" >> /etc/apt/sources.list \ 45 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 46 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 47 | && apt-get update 48 | 49 | RUN apt-get update \ 50 | && apt-get install -y -q --allow-unauthenticated \ 51 | libzmq3-dev \ 52 | sawtooth-smallbank-tp-go \ 53 | && apt-get clean \ 54 | && rm -rf /var/lib/apt/lists/* 55 | 56 | EXPOSE 4004/tcp 57 | 58 | CMD ["smallbank-tp-go", "-C", "tcp://validator:4004"] 59 | -------------------------------------------------------------------------------- /docker/sawtooth-int-xo-tp-go: -------------------------------------------------------------------------------- 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 | # Description: 17 | # Builds an image with Sawtooth TP Xo Go installed. 18 | # 19 | # Build: 20 | # This image should be built using `build_all installed`. 21 | # 22 | # Run: 23 | # $ docker run sawtooth-xo-tp-go 24 | 25 | FROM ubuntu:bionic 26 | 27 | RUN apt-get update \ 28 | && apt-get install gnupg -y 29 | 30 | LABEL "install-type"="local-debs" 31 | 32 | RUN apt-get update \ 33 | && apt-get install -y -q \ 34 | dpkg-dev \ 35 | && apt-get clean \ 36 | && rm -rf /var/lib/apt/lists/* \ 37 | && mkdir /debs 38 | 39 | COPY sawtooth-xo-tp-go*.deb /debs/ 40 | 41 | RUN cd /debs \ 42 | && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz \ 43 | && echo "deb file:/debs ./" >> /etc/apt/sources.list \ 44 | && echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/ci bionic universe" >> /etc/apt/sources.list \ 45 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 46 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 47 | && apt-get update 48 | 49 | RUN apt-get update \ 50 | && apt-get install -y -q --allow-unauthenticated \ 51 | libssl-dev \ 52 | libzmq3-dev \ 53 | sawtooth-xo-tp-go \ 54 | && apt-get clean \ 55 | && rm -rf /var/lib/apt/lists/* 56 | 57 | 58 | EXPOSE 4004/tcp 59 | 60 | CMD ["xo-tp-go", "-C", "tcp://validator:4004"] 61 | -------------------------------------------------------------------------------- /examples/devmode_consensus/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/hyperledger/sawtooth-devmode-go/examples/devmode_consensus 2 | 3 | go 1.16 4 | 5 | replace github.com/hyperledger/sawtooth-sdk-go => ../../ 6 | 7 | require ( 8 | github.com/hyperledger/sawtooth-sdk-go v0.0.0-00010101000000-000000000000 9 | github.com/jessevdk/go-flags v1.4.0 10 | ) 11 | -------------------------------------------------------------------------------- /examples/devmode_consensus/main.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2022 Grid 7, LLC (DBA Taekion) 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 | "math/rand" 23 | "os" 24 | "syscall" 25 | "time" 26 | 27 | "github.com/hyperledger/sawtooth-sdk-go/consensus" 28 | "github.com/hyperledger/sawtooth-sdk-go/logging" 29 | "github.com/jessevdk/go-flags" 30 | ) 31 | 32 | // init is a special function in Go that is run once before main. 33 | func init() { 34 | // initialize RNG 35 | rand.Seed(time.Now().UnixNano()) 36 | } 37 | 38 | type Opts struct { 39 | Verbose []bool `short:"v" long:"verbose" description:"Increase verbosity"` 40 | Connect string `short:"C" long:"connect" description:"Validator consensus endpoint to connect to" default:"tcp://localhost:5050"` 41 | } 42 | 43 | func main() { 44 | var opts Opts 45 | 46 | logger := logging.Get() 47 | 48 | parser := flags.NewParser(&opts, flags.Default) 49 | remaining, err := parser.Parse() 50 | if err != nil { 51 | if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { 52 | os.Exit(0) 53 | } else { 54 | logger.Errorf("Failed to parse args: %v", err) 55 | os.Exit(2) 56 | } 57 | } 58 | 59 | if len(remaining) > 0 { 60 | fmt.Printf("Error: Unrecognized arguments passed: %v\n", remaining) 61 | os.Exit(2) 62 | } 63 | 64 | endpoint := opts.Connect 65 | 66 | switch len(opts.Verbose) { 67 | case 2: 68 | logger.SetLevel(logging.DEBUG) 69 | case 1: 70 | logger.SetLevel(logging.INFO) 71 | default: 72 | logger.SetLevel(logging.WARN) 73 | } 74 | 75 | engine := consensus.NewConsensusEngine(endpoint, &DevmodeEngineImpl{}) 76 | engine.ShutdownOnSignal(syscall.SIGINT, syscall.SIGTERM) 77 | engine.Start() 78 | if err != nil { 79 | logger.Errorf("Processor stopped: %v", err) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /examples/intkey_go/intkey-tests.dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | 16 | FROM ubuntu:bionic 17 | 18 | RUN apt-get update \ 19 | && apt-get install gnupg -y 20 | 21 | RUN echo "deb http://repo.sawtooth.me/ubuntu/nightly bionic universe" >> /etc/apt/sources.list \ 22 | && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \ 23 | && apt-get update 24 | 25 | RUN apt-get install -y -q \ 26 | python3-sawtooth-integration \ 27 | python3-sawtooth-intkey-tests \ 28 | python3-sawtooth-sdk 29 | 30 | RUN apt-get install -y -q --allow-downgrades \ 31 | git \ 32 | python3 \ 33 | python3-stdeb 34 | 35 | RUN apt-get install -y -q --allow-downgrades \ 36 | python3-grpcio \ 37 | python3-grpcio-tools \ 38 | python3-protobuf 39 | 40 | RUN apt-get install -y -q --allow-downgrades \ 41 | net-tools \ 42 | python3-cbor \ 43 | python3-colorlog \ 44 | python3-secp256k1 \ 45 | python3-toml \ 46 | python3-yaml \ 47 | python3-zmq 48 | 49 | RUN apt-get install -y -q \ 50 | python3-cov-core \ 51 | python3-nose2 \ 52 | python3-pip 53 | 54 | RUN pip3 install \ 55 | coverage --upgrade 56 | 57 | RUN mkdir -p /var/log/sawtooth 58 | 59 | ENV PATH=$PATH:/project/sawtooth-core/bin 60 | 61 | WORKDIR /project/sawtooth-core 62 | -------------------------------------------------------------------------------- /examples/intkey_go/packaging/systemd/etc/default/sawtooth-intkey-tp-go: -------------------------------------------------------------------------------- 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 | #SAWTOOTH_INTKEY_TP_GO_ARGS=-v -C tcp://localhost:4004 17 | -------------------------------------------------------------------------------- /examples/intkey_go/packaging/systemd/lib/systemd/system/sawtooth-intkey-tp-go.service: -------------------------------------------------------------------------------- 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 | [Unit] 17 | Description=Sawtooth Intkey TP Go 18 | After=network.target 19 | 20 | [Service] 21 | User=sawtooth 22 | Group=sawtooth 23 | EnvironmentFile=-/etc/default/sawtooth-intkey-tp-go 24 | ExecStart=/usr/bin/intkey-tp-go $SAWTOOTH_INTKEY_TP_GO_ARGS 25 | Restart=on-failure 26 | 27 | [Install] 28 | WantedBy=multi-user.target 29 | -------------------------------------------------------------------------------- /examples/intkey_go/packaging/ubuntu/changelog: -------------------------------------------------------------------------------- 1 | sawtooth-intkey-tp-go (@VERSION@) unstable; urgency=low 2 | 3 | * change data here 4 | 5 | -- Hyperledger Sawtooth 6 | -------------------------------------------------------------------------------- /examples/intkey_go/packaging/ubuntu/control: -------------------------------------------------------------------------------- 1 | Source: sawtooth-intkey-tp-go 2 | Maintainer: Hyperledger Sawtooth 3 | Section: go 4 | Priority: optional 5 | Standards-Version: 3.9.6 6 | Homepage: https://github.com/hyperledger/sawtooth-core 7 | Package: sawtooth-intkey-tp-go 8 | Architecture: all 9 | Depends: libssl-dev, libzmq3-dev 10 | Description: Sawtooth Intkey TP Go 11 | Version: @VERSION@ 12 | -------------------------------------------------------------------------------- /examples/intkey_go/packaging/ubuntu/postinst: -------------------------------------------------------------------------------- 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 | set -e 19 | 20 | user="sawtooth" 21 | group="sawtooth" 22 | 23 | if ! getent group $group > /dev/null; then 24 | addgroup --quiet --system $group 25 | fi 26 | 27 | if ! getent passwd $user > /dev/null; then 28 | adduser --quiet --system --ingroup $group $user 29 | fi 30 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey/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 | intkey "github.com/hyperledger/sawtooth-sdk-go/examples/intkey_go/src/sawtooth_intkey/handler" 23 | "github.com/hyperledger/sawtooth-sdk-go/logging" 24 | "github.com/hyperledger/sawtooth-sdk-go/processor" 25 | flags "github.com/jessevdk/go-flags" 26 | "os" 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 | Queue uint `long:"max-queue-size" description:"Set the maximum queue size before rejecting process requests" default:"100"` 34 | Threads uint `long:"worker-thread-count" description:"Set the number of worker threads to use for processing requests in parallel" default:"0"` 35 | } 36 | 37 | func main() { 38 | var opts Opts 39 | 40 | logger := logging.Get() 41 | 42 | parser := flags.NewParser(&opts, flags.Default) 43 | remaining, err := parser.Parse() 44 | if err != nil { 45 | if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { 46 | os.Exit(0) 47 | } else { 48 | logger.Errorf("Failed to parse args: %v", err) 49 | os.Exit(2) 50 | } 51 | } 52 | 53 | if len(remaining) > 0 { 54 | fmt.Printf("Error: Unrecognized arguments passed: %v\n", remaining) 55 | os.Exit(2) 56 | } 57 | 58 | endpoint := opts.Connect 59 | 60 | switch len(opts.Verbose) { 61 | case 2: 62 | logger.SetLevel(logging.DEBUG) 63 | case 1: 64 | logger.SetLevel(logging.INFO) 65 | default: 66 | logger.SetLevel(logging.WARN) 67 | } 68 | 69 | prefix := intkey.Hexdigest("intkey")[:6] 70 | handler := intkey.NewIntkeyHandler(prefix) 71 | processor := processor.NewTransactionProcessor(endpoint) 72 | processor.SetMaxQueueSize(opts.Queue) 73 | if opts.Threads > 0 { 74 | processor.SetThreadCount(opts.Threads) 75 | } 76 | processor.AddHandler(handler) 77 | processor.ShutdownOnSignal(syscall.SIGINT, syscall.SIGTERM) 78 | err = processor.Start() 79 | if err != nil { 80 | logger.Error("Processor stopped: ", err) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey_client/constants.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 main 19 | 20 | const ( 21 | // String literals 22 | FAMILY_NAME string = "intkey" 23 | FAMILY_VERSION string = "1.0" 24 | DISTRIBUTION_NAME string = "sawtooth-intkey" 25 | DEFAULT_URL string = "http://127.0.0.1:8008" 26 | // Verbs 27 | VERB_SET string = "set" 28 | VERB_INC string = "inc" 29 | VERB_DEC string = "dec" 30 | // APIs 31 | BATCH_SUBMIT_API string = "batches" 32 | BATCH_STATUS_API string = "batch_statuses" 33 | STATE_API string = "state" 34 | // Content types 35 | CONTENT_TYPE_OCTET_STREAM string = "application/octet-stream" 36 | // Integer literals 37 | FAMILY_NAMESPACE_ADDRESS_LENGTH uint = 6 38 | FAMILY_VERB_ADDRESS_LENGTH uint = 64 39 | ) 40 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey_client/dec.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 main 19 | 20 | import ( 21 | "github.com/jessevdk/go-flags" 22 | "strconv" 23 | ) 24 | 25 | type Dec struct { 26 | Args struct { 27 | Name string `positional-arg-name:"name" required:"true" description:"Identify name of key to decrement"` 28 | Value string `positional-arg-name:"value" required:"true" description:"Specify amount to decrement"` 29 | } `positional-args:"true"` 30 | Url string `long:"url" description:"Specify URL of REST API"` 31 | Keyfile string `long:"keyfile" description:"Identify file containing user's private key"` 32 | Wait uint `long:"wait" description:"Set time, in seconds, to wait for transaction to commit"` 33 | } 34 | 35 | func (args *Dec) Name() string { 36 | return "dec" 37 | } 38 | 39 | func (args *Dec) KeyfilePassed() string { 40 | return args.Keyfile 41 | } 42 | 43 | func (args *Dec) UrlPassed() string { 44 | return args.Url 45 | } 46 | 47 | func (args *Dec) Register(parent *flags.Command) error { 48 | _, err := parent.AddCommand(args.Name(), "Decrements an intkey value", "Sends an intkey transaction to decrement by .", args) 49 | if err != nil { 50 | return err 51 | } 52 | return nil 53 | } 54 | 55 | func (args *Dec) Run() error { 56 | // Construct client 57 | name := args.Args.Name 58 | value, err := strconv.Atoi(args.Args.Value) 59 | if err != nil { 60 | return err 61 | } 62 | wait := args.Wait 63 | 64 | intkeyClient, err := GetClient(args, true) 65 | if err != nil { 66 | return err 67 | } 68 | _, err = intkeyClient.Dec(name, uint(value), wait) 69 | return err 70 | } 71 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey_client/inc.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 main 19 | 20 | import ( 21 | "github.com/jessevdk/go-flags" 22 | "strconv" 23 | ) 24 | 25 | type Inc struct { 26 | Args struct { 27 | Name string `positional-arg-name:"name" required:"true" description:"Identify name of key to increment"` 28 | Value string `positional-arg-name:"value" required:"true" description:"Specify amount to increment"` 29 | } `positional-args:"true"` 30 | Url string `long:"url" description:"Specify URL of REST API"` 31 | Keyfile string `long:"keyfile" description:"Identify file containing user's private key"` 32 | Wait uint `long:"wait" description:"Set time, in seconds, to wait for transaction to commit"` 33 | } 34 | 35 | func (args *Inc) Name() string { 36 | return "inc" 37 | } 38 | 39 | func (args *Inc) KeyfilePassed() string { 40 | return args.Keyfile 41 | } 42 | 43 | func (args *Inc) UrlPassed() string { 44 | return args.Url 45 | } 46 | 47 | func (args *Inc) Register(parent *flags.Command) error { 48 | _, err := parent.AddCommand(args.Name(), "Increments an intkey value", "Sends an intkey transaction to increment by .", args) 49 | if err != nil { 50 | return err 51 | } 52 | return nil 53 | } 54 | 55 | func (args *Inc) Run() error { 56 | // Construct client 57 | name := args.Args.Name 58 | value, err := strconv.Atoi(args.Args.Value) 59 | if err != nil { 60 | return err 61 | } 62 | wait := args.Wait 63 | 64 | intkeyClient, err := GetClient(args, true) 65 | if err != nil { 66 | return err 67 | } 68 | _, err = intkeyClient.Inc(name, uint(value), wait) 69 | return err 70 | } 71 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey_client/list.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 main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | ) 24 | 25 | type List struct { 26 | Url string `long:"url" description:"Specify URL of REST API"` 27 | } 28 | 29 | func (args *List) Name() string { 30 | return "list" 31 | } 32 | 33 | func (args *List) KeyfilePassed() string { 34 | return "" 35 | } 36 | 37 | func (args *List) UrlPassed() string { 38 | return args.Url 39 | } 40 | 41 | func (args *List) Register(parent *flags.Command) error { 42 | _, err := parent.AddCommand(args.Name(), "Displays all intkey values", "Shows the values of all keys in intkey state.", args) 43 | if err != nil { 44 | return err 45 | } 46 | return nil 47 | } 48 | 49 | func (args *List) Run() error { 50 | // Construct client 51 | intkeyClient, err := GetClient(args, false) 52 | if err != nil { 53 | return err 54 | } 55 | pairs, err := intkeyClient.List() 56 | if err != nil { 57 | return err 58 | } 59 | for _, pair := range pairs { 60 | for k, v := range pair { 61 | fmt.Println(k, ": ", v) 62 | } 63 | } 64 | return nil 65 | } 66 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey_client/main.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 main 19 | 20 | import ( 21 | "crypto/sha512" 22 | "encoding/hex" 23 | "fmt" 24 | "github.com/hyperledger/sawtooth-sdk-go/logging" 25 | flags "github.com/jessevdk/go-flags" 26 | "os" 27 | "os/user" 28 | "path" 29 | "strings" 30 | ) 31 | 32 | // All subcommands implement this interface 33 | type Command interface { 34 | Register(*flags.Command) error 35 | Name() string 36 | KeyfilePassed() string 37 | UrlPassed() string 38 | Run() error 39 | } 40 | 41 | type Opts struct { 42 | Verbose []bool `short:"v" long:"verbose" description:"Enable more verbose output"` 43 | Version bool `short:"V" long:"version" description:"Display version information"` 44 | } 45 | 46 | var DISTRIBUTION_VERSION string 47 | 48 | var logger *logging.Logger = logging.Get() 49 | 50 | func init() { 51 | if len(DISTRIBUTION_VERSION) == 0 { 52 | DISTRIBUTION_VERSION = "Unknown" 53 | } 54 | } 55 | 56 | func main() { 57 | arguments := os.Args[1:] 58 | for _, arg := range arguments { 59 | if arg == "-V" || arg == "--version" { 60 | fmt.Println(DISTRIBUTION_NAME + " (Hyperledger Sawtooth) version " + DISTRIBUTION_VERSION) 61 | os.Exit(0) 62 | } 63 | } 64 | 65 | var opts Opts 66 | parser := flags.NewParser(&opts, flags.Default) 67 | parser.Command.Name = "intkey" 68 | 69 | // Add sub-commands 70 | commands := []Command{ 71 | &Set{}, 72 | &Inc{}, 73 | &Dec{}, 74 | &Show{}, 75 | &List{}, 76 | } 77 | for _, cmd := range commands { 78 | err := cmd.Register(parser.Command) 79 | if err != nil { 80 | logger.Errorf("Couldn't register command %v: %v", cmd.Name(), err) 81 | os.Exit(1) 82 | } 83 | } 84 | 85 | remaining, err := parser.Parse() 86 | if e, ok := err.(*flags.Error); ok { 87 | if e.Type == flags.ErrHelp { 88 | return 89 | } else { 90 | os.Exit(1) 91 | } 92 | } 93 | 94 | if len(remaining) > 0 { 95 | fmt.Println("Error: Unrecognized arguments passed: ", remaining) 96 | os.Exit(2) 97 | } 98 | 99 | switch len(opts.Verbose) { 100 | case 2: 101 | logger.SetLevel(logging.DEBUG) 102 | case 1: 103 | logger.SetLevel(logging.INFO) 104 | default: 105 | logger.SetLevel(logging.WARN) 106 | } 107 | 108 | // If a sub-command was passed, run it 109 | if parser.Command.Active == nil { 110 | os.Exit(2) 111 | } 112 | 113 | name := parser.Command.Active.Name 114 | for _, cmd := range commands { 115 | if cmd.Name() == name { 116 | err := cmd.Run() 117 | if err != nil { 118 | fmt.Println("Error: ", err) 119 | os.Exit(1) 120 | } 121 | return 122 | } 123 | } 124 | 125 | fmt.Println("Error: Command not found: ", name) 126 | } 127 | 128 | func Sha512HashValue(value string) string { 129 | hashHandler := sha512.New() 130 | hashHandler.Write([]byte(value)) 131 | return strings.ToLower(hex.EncodeToString(hashHandler.Sum(nil))) 132 | } 133 | 134 | func GetClient(args Command, readFile bool) (IntkeyClient, error) { 135 | url := args.UrlPassed() 136 | if url == "" { 137 | url = DEFAULT_URL 138 | } 139 | keyfile := "" 140 | if readFile { 141 | var err error 142 | keyfile, err = GetKeyfile(args.KeyfilePassed()) 143 | if err != nil { 144 | return IntkeyClient{}, err 145 | } 146 | } 147 | return NewIntkeyClient(url, keyfile) 148 | } 149 | 150 | func GetKeyfile(keyfile string) (string, error) { 151 | if keyfile == "" { 152 | username, err := user.Current() 153 | if err != nil { 154 | return "", err 155 | } 156 | return path.Join( 157 | username.HomeDir, ".sawtooth", "keys", username.Username+".priv"), nil 158 | } else { 159 | return keyfile, nil 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey_client/main_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 main 19 | 20 | import ( 21 | "testing" 22 | ) 23 | 24 | func Test_Sha512Compute(t *testing.T) { 25 | sha512OfIntkey := "1cf126a27a1fd9ba83e819ebff8c9f98ec8976f39cce35e984242a2ee40368fd8704c8f6147d653fb02c17e666cfc89c0ddc54d5b48d1cabdfed4ec124f99bdb" 26 | computedSha512OfIntkey := Sha512HashValue(FAMILY_NAME) 27 | if sha512OfIntkey != computedSha512OfIntkey { 28 | t.Errorf("Sha512 computed doesn't match \nExpected: %s \nGot: %s \n", 29 | sha512OfIntkey, computedSha512OfIntkey) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey_client/set.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 main 19 | 20 | import ( 21 | "github.com/jessevdk/go-flags" 22 | "strconv" 23 | ) 24 | 25 | type Set struct { 26 | Args struct { 27 | Name string `positional-arg-name:"name" required:"true" description:"Name of key to set"` 28 | Value string `positional-arg-name:"value" required:"true" description:"Amount to set"` 29 | } `positional-args:"true"` 30 | Url string `long:"url" description:"Specify URL of REST API"` 31 | Keyfile string `long:"keyfile" description:"Identify file containing user's private key"` 32 | Wait uint `long:"wait" description:"Set time, in seconds, to wait for transaction to commit"` 33 | } 34 | 35 | func (args *Set) Name() string { 36 | return "set" 37 | } 38 | 39 | func (args *Set) KeyfilePassed() string { 40 | return args.Keyfile 41 | } 42 | 43 | func (args *Set) UrlPassed() string { 44 | return args.Url 45 | } 46 | 47 | func (args *Set) Register(parent *flags.Command) error { 48 | _, err := parent.AddCommand(args.Name(), "Sets an intkey value", "Sends an intkey transaction to set to .", args) 49 | if err != nil { 50 | return err 51 | } 52 | return nil 53 | } 54 | 55 | func (args *Set) Run() error { 56 | // Construct client 57 | name := args.Args.Name 58 | value, err := strconv.Atoi(args.Args.Value) 59 | if err != nil { 60 | return err 61 | } 62 | wait := args.Wait 63 | 64 | intkeyClient, err := GetClient(args, true) 65 | if err != nil { 66 | return err 67 | } 68 | _, err = intkeyClient.Set(name, uint(value), wait) 69 | return err 70 | } 71 | -------------------------------------------------------------------------------- /examples/intkey_go/src/sawtooth_intkey_client/show.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 main 19 | 20 | import ( 21 | "fmt" 22 | "github.com/jessevdk/go-flags" 23 | ) 24 | 25 | type Show struct { 26 | Args struct { 27 | Name string `positional-arg-name:"name" required:"true" description:"Name of key to show"` 28 | } `positional-args:"true"` 29 | Url string `long:"url" description:"Specify URL of REST API"` 30 | } 31 | 32 | func (args *Show) Name() string { 33 | return "show" 34 | } 35 | 36 | func (args *Show) KeyfilePassed() string { 37 | return "" 38 | } 39 | 40 | func (args *Show) UrlPassed() string { 41 | return args.Url 42 | } 43 | 44 | func (args *Show) Register(parent *flags.Command) error { 45 | _, err := parent.AddCommand(args.Name(), "Displays the specified intkey value", "Shows the value of the key .", args) 46 | if err != nil { 47 | return err 48 | } 49 | return nil 50 | } 51 | 52 | func (args *Show) Run() error { 53 | // Construct client 54 | name := args.Args.Name 55 | intkeyClient, err := GetClient(args, false) 56 | if err != nil { 57 | return err 58 | } 59 | value, err := intkeyClient.Show(name) 60 | if err != nil { 61 | return err 62 | } 63 | fmt.Println(name, ": ", value) 64 | return nil 65 | } 66 | -------------------------------------------------------------------------------- /examples/intkey_go/tests/test_intkey_smoke_go.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 | settings-tp: 21 | image: hyperledger/sawtooth-settings-tp 22 | depends_on: 23 | - validator 24 | command: settings-tp -vv -C tcp://validator:4004 25 | stop_signal: SIGKILL 26 | 27 | intkey-tp-go: 28 | image: sawtooth-intkey-tp-go:$ISOLATION_ID 29 | build: 30 | context: ../../.. 31 | dockerfile: examples/intkey_go/Dockerfile-installed-${DISTRO} 32 | depends_on: 33 | - validator 34 | command: intkey-tp-go -v -C tcp://validator:4004 35 | stop_signal: SIGKILL 36 | 37 | validator: 38 | image: hyperledger/sawtooth-validator 39 | expose: 40 | - 4004 41 | - 5050 42 | command: "bash -c \"\ 43 | sawadm keygen && \ 44 | sawset genesis \ 45 | -k /etc/sawtooth/keys/validator.priv \ 46 | -o config-genesis.batch && \ 47 | sawset proposal create \ 48 | -k /etc/sawtooth/keys/validator.priv \ 49 | sawtooth.consensus.algorithm.name=Devmode \ 50 | sawtooth.consensus.algorithm.version=0.1 \ 51 | -o config.batch && \ 52 | sawadm genesis config-genesis.batch config.batch && \ 53 | sawtooth-validator -v \ 54 | --endpoint tcp://validator:8800 \ 55 | --bind component:tcp://eth0:4004 \ 56 | --bind network:tcp://eth0:8800 \ 57 | --bind consensus:tcp://eth0:5050 \ 58 | \"" 59 | stop_signal: SIGKILL 60 | 61 | 62 | rest-api: 63 | image: hyperledger/sawtooth-rest-api 64 | expose: 65 | - 8008 66 | depends_on: 67 | - validator 68 | command: sawtooth-rest-api -v --connect tcp://validator:4004 --bind rest-api:8008 69 | stop_signal: SIGKILL 70 | 71 | devmode-rust-engine: 72 | image: hyperledger/sawtooth-devmode-engine-rust 73 | expose: 74 | - 5050 75 | depends_on: 76 | - validator 77 | command: devmode-engine-rust -v --connect tcp://validator:5050 78 | stop_signal: SIGKILL 79 | 80 | test-intkey-smoke-go: 81 | image: intkey-tests:$ISOLATION_ID 82 | build: 83 | context: ../ 84 | dockerfile: ./intkey-tests.dockerfile 85 | depends_on: 86 | - validator 87 | - rest-api 88 | - intkey-tp-go 89 | - settings-tp 90 | command: nose2-3 91 | -v 92 | -s /data/tests/intkey 93 | test_intkey_smoke.TestIntkeySmoke 94 | stop_signal: SIGKILL 95 | -------------------------------------------------------------------------------- /examples/intkey_go/tests/test_tp_intkey_go.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 | intkey-tp-go: 21 | build: 22 | context: ../../.. 23 | dockerfile: examples/intkey_go/Dockerfile-installed-${DISTRO} 24 | image: sawtooth-intkey-tp-go:$ISOLATION_ID 25 | command: intkey-tp-go -vv -C tcp://test-intkey-tp-go:4004 26 | stop_signal: SIGKILL 27 | 28 | test-intkey-tp-go: 29 | image: intkey-tests:$ISOLATION_ID 30 | build: 31 | context: ../ 32 | dockerfile: ./intkey-tests.dockerfile 33 | image: intkey-tests:$ISOLATION_ID 34 | expose: 35 | - 4004 36 | command: nose2-3 37 | -v 38 | -s /data/tests/intkey 39 | test_tp_intkey 40 | stop_signal: SIGKILL 41 | environment: 42 | TEST_BIND: "tcp://eth0:4004" 43 | PYTHONPATH: "/data/tests/intkey/" 44 | -------------------------------------------------------------------------------- /examples/noop_go/packaging/systemd/etc/default/sawtooth-noop-tp-go: -------------------------------------------------------------------------------- 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 | #SAWTOOTH_NOOP_TP_GO_ARGS=-v -C tcp://localhost:4004 17 | -------------------------------------------------------------------------------- /examples/noop_go/packaging/systemd/lib/systemd/system/sawtooth-noop-tp-go.service: -------------------------------------------------------------------------------- 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 | [Unit] 17 | Description=Sawtooth Noop TP Go 18 | After=network.target 19 | 20 | [Service] 21 | User=sawtooth 22 | Group=sawtooth 23 | EnvironmentFile=-/etc/default/sawtooth-noop-tp-go 24 | ExecStart=/usr/bin/noop-tp-go $SAWTOOTH_NOOP_TP_GO_ARGS 25 | Restart=on-failure 26 | 27 | [Install] 28 | WantedBy=multi-user.target 29 | -------------------------------------------------------------------------------- /examples/noop_go/packaging/ubuntu/changelog: -------------------------------------------------------------------------------- 1 | sawtooth-noop-tp-go (@VERSION@) unstable; urgency=low 2 | 3 | * change data here 4 | 5 | -- Hyperledger Sawtooth 6 | -------------------------------------------------------------------------------- /examples/noop_go/packaging/ubuntu/control: -------------------------------------------------------------------------------- 1 | Source: sawtooth-noop-tp-go 2 | Maintainer: Hyperledger Sawtooth 3 | Section: go 4 | Priority: optional 5 | Standards-Version: 3.9.6 6 | Homepage: https://github.com/hyperledger/sawtooth-core 7 | Package: sawtooth-noop-tp-go 8 | Architecture: all 9 | Depends: libssl-dev, libzmq3-dev 10 | Description: Sawtooth Noop TP Go 11 | Version: @VERSION@ 12 | -------------------------------------------------------------------------------- /examples/noop_go/packaging/ubuntu/postinst: -------------------------------------------------------------------------------- 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 | set -e 19 | 20 | user="sawtooth" 21 | group="sawtooth" 22 | 23 | if ! getent group $group > /dev/null; then 24 | addgroup --quiet --system $group 25 | fi 26 | 27 | if ! getent passwd $user > /dev/null; then 28 | adduser --quiet --system --ingroup $group $user 29 | fi 30 | -------------------------------------------------------------------------------- /examples/noop_go/src/sawtooth_noop/handler/handler.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 | "crypto/sha512" 22 | "encoding/hex" 23 | "github.com/hyperledger/sawtooth-sdk-go/logging" 24 | "github.com/hyperledger/sawtooth-sdk-go/processor" 25 | "github.com/hyperledger/sawtooth-sdk-go/protobuf/processor_pb2" 26 | "strings" 27 | ) 28 | 29 | var logger *logging.Logger = logging.Get() 30 | 31 | type NoopHandler struct { 32 | namespace string 33 | } 34 | 35 | func NewNoopHandler(namespace string) *NoopHandler { 36 | return &NoopHandler{ 37 | namespace: namespace, 38 | } 39 | } 40 | 41 | const FAMILY_NAME = "noop" 42 | 43 | func (self *NoopHandler) FamilyName() string { 44 | return FAMILY_NAME 45 | } 46 | func (self *NoopHandler) FamilyVersions() []string { 47 | return []string{"1.0"} 48 | } 49 | func (self *NoopHandler) Namespaces() []string { 50 | return []string{self.namespace} 51 | } 52 | 53 | func (self *NoopHandler) Apply(request *processor_pb2.TpProcessRequest, state *processor.Context) error { 54 | return nil 55 | } 56 | 57 | func Hexdigest(str string) string { 58 | hash := sha512.New() 59 | hash.Write([]byte(str)) 60 | hashBytes := hash.Sum(nil) 61 | return strings.ToLower(hex.EncodeToString(hashBytes)) 62 | } 63 | -------------------------------------------------------------------------------- /examples/noop_go/src/sawtooth_noop/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 | "flag" 22 | noop "github.com/hyperledger/sawtooth-sdk-go/examples/noop_go/src/sawtooth_noop/handler" 23 | "github.com/hyperledger/sawtooth-sdk-go/logging" 24 | "github.com/hyperledger/sawtooth-sdk-go/processor" 25 | "syscall" 26 | ) 27 | 28 | func main() { 29 | v := flag.Bool("v", false, "Info level logging") 30 | vv := flag.Bool("vv", false, "Debug level logging") 31 | endpoint := "tcp://localhost:4004" 32 | 33 | flag.Parse() 34 | args := flag.Args() 35 | if len(args) > 0 { 36 | // Overwrite the default endpoint if specified 37 | endpoint = args[0] 38 | } 39 | 40 | level := logging.WARN 41 | if *v { 42 | level = logging.INFO 43 | } 44 | if *vv { 45 | level = logging.DEBUG 46 | } 47 | 48 | logger := logging.Get() 49 | logger.SetLevel(level) 50 | 51 | prefix := noop.Hexdigest("noop")[:6] 52 | handler := noop.NewNoopHandler(prefix) 53 | processor := processor.NewTransactionProcessor(endpoint) 54 | processor.AddHandler(handler) 55 | processor.ShutdownOnSignal(syscall.SIGINT, syscall.SIGTERM) 56 | err := processor.Start() 57 | if err != nil { 58 | logger.Error("Processor stopped: ", err) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/smallbank/protos/smallbank.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 | option go_package = "protos/smallbank_pb2"; 18 | 19 | message Account { 20 | // Customer ID 21 | uint32 customer_id = 1; 22 | 23 | // Customer Name 24 | string customer_name = 2; 25 | 26 | // Savings Balance (in cents to avoid float) 27 | uint32 savings_balance = 3; 28 | 29 | // Checking Balance (in cents to avoid float) 30 | uint32 checking_balance = 4; 31 | } 32 | 33 | message SmallbankTransactionPayload { 34 | message CreateAccountTransactionData { 35 | // The CreateAccountTransaction creates an account 36 | 37 | // Customer ID 38 | uint32 customer_id = 1; 39 | 40 | // Customer Name 41 | string customer_name = 2; 42 | 43 | // Initial Savings Balance (in cents to avoid float) 44 | uint32 initial_savings_balance = 3; 45 | 46 | // Initial Checking Balance (in cents to avoid float) 47 | uint32 initial_checking_balance = 4; 48 | } 49 | 50 | message DepositCheckingTransactionData { 51 | // The DepositCheckingTransction adds an amount to the customer's 52 | // checking account. 53 | 54 | // Customer ID 55 | uint32 customer_id = 1; 56 | 57 | // Amount 58 | uint32 amount = 2; 59 | } 60 | 61 | message WriteCheckTransactionData { 62 | // The WriteCheckTransaction removes an amount from the customer's 63 | // checking account. 64 | 65 | // Customer ID 66 | uint32 customer_id = 1; 67 | 68 | // Amount 69 | uint32 amount = 2; 70 | } 71 | 72 | message TransactSavingsTransactionData { 73 | // The TransactSavingsTransaction adds an amount to the customer's 74 | // savings account. Amount may be a negative number. 75 | 76 | // Customer ID 77 | uint32 customer_id = 1; 78 | 79 | // Amount 80 | int32 amount = 2; 81 | } 82 | 83 | message SendPaymentTransactionData { 84 | // The SendPaymentTransaction transfers an amount from one customer's 85 | // checking account to another customer's checking account. 86 | 87 | // Source Customer ID 88 | uint32 source_customer_id = 1; 89 | 90 | // Destination Customer ID 91 | uint32 dest_customer_id = 2; 92 | 93 | // Amount 94 | uint32 amount = 3; 95 | } 96 | 97 | message AmalgamateTransactionData { 98 | // The AmalgamateTransaction transfers the entire contents of one 99 | // customer's savings account into another customer's checking 100 | // account. 101 | 102 | // Source Customer ID 103 | uint32 source_customer_id = 1; 104 | 105 | // Destination Customer ID 106 | uint32 dest_customer_id = 2; 107 | } 108 | 109 | enum PayloadType { 110 | PAYLOAD_TYPE_UNSET = 0; 111 | CREATE_ACCOUNT = 1; 112 | DEPOSIT_CHECKING = 2; 113 | WRITE_CHECK = 3; 114 | TRANSACT_SAVINGS = 4; 115 | SEND_PAYMENT = 5; 116 | AMALGAMATE = 6; 117 | } 118 | 119 | PayloadType payload_type = 1; 120 | CreateAccountTransactionData create_account = 2; 121 | DepositCheckingTransactionData deposit_checking = 3; 122 | WriteCheckTransactionData write_check = 4; 123 | TransactSavingsTransactionData transact_savings = 5; 124 | SendPaymentTransactionData send_payment = 6; 125 | AmalgamateTransactionData amalgamate = 7; 126 | } 127 | -------------------------------------------------------------------------------- /examples/smallbank/smallbank_go/packaging/systemd/etc/default/sawtooth-smallbank-tp-go: -------------------------------------------------------------------------------- 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 | #SAWTOOTH_SMALLBANK_TP_GO_ARGS=-v -C tcp://localhost:4004 17 | -------------------------------------------------------------------------------- /examples/smallbank/smallbank_go/packaging/systemd/lib/systemd/system/sawtooth-smallbank-tp-go.service: -------------------------------------------------------------------------------- 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 | [Unit] 17 | Description=Sawtooth Smallbank TP Go 18 | After=network.target 19 | 20 | [Service] 21 | User=sawtooth 22 | Group=sawtooth 23 | EnvironmentFile=-/etc/default/sawtooth-smallbank-tp-go 24 | ExecStart=/usr/bin/smallbank-tp-go $SAWTOOTH_SMALLBANK_TP_GO_ARGS 25 | Restart=on-failure 26 | 27 | [Install] 28 | WantedBy=multi-user.target 29 | -------------------------------------------------------------------------------- /examples/smallbank/smallbank_go/packaging/ubuntu/changelog: -------------------------------------------------------------------------------- 1 | sawtooth-smallbank-tp-go (@VERSION@) unstable; urgency=low 2 | 3 | * change data here 4 | 5 | -- Hyperledger Sawtooth 6 | -------------------------------------------------------------------------------- /examples/smallbank/smallbank_go/packaging/ubuntu/control: -------------------------------------------------------------------------------- 1 | Source: sawtooth-smallbank-tp-go 2 | Maintainer: Hyperledger Sawtooth 3 | Section: go 4 | Priority: optional 5 | Standards-Version: 3.9.6 6 | Homepage: https://github.com/hyperledger/sawtooth-core 7 | Package: sawtooth-smallbank-tp-go 8 | Architecture: all 9 | Depends: libssl-dev, libzmq3-dev 10 | Description: Sawtooth Smallbank TP Go 11 | Version: @VERSION@ 12 | -------------------------------------------------------------------------------- /examples/smallbank/smallbank_go/packaging/ubuntu/postinst: -------------------------------------------------------------------------------- 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 | set -e 19 | 20 | user="sawtooth" 21 | group="sawtooth" 22 | 23 | if ! getent group $group > /dev/null; then 24 | addgroup --quiet --system $group 25 | fi 26 | 27 | if ! getent passwd $user > /dev/null; then 28 | adduser --quiet --system --ingroup $group $user 29 | fi 30 | -------------------------------------------------------------------------------- /examples/smallbank/smallbank_go/src/sawtooth_smallbank/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 | package main 18 | 19 | import ( 20 | smallbank "github.com/hyperledger/sawtooth-sdk-go/examples/smallbank/smallbank_go/src/sawtooth_smallbank/handler" 21 | "github.com/hyperledger/sawtooth-sdk-go/logging" 22 | "github.com/hyperledger/sawtooth-sdk-go/processor" 23 | flags "github.com/jessevdk/go-flags" 24 | "os" 25 | "syscall" 26 | ) 27 | 28 | var opts struct { 29 | Verbose []bool `short:"v" long:"verbose" description:"Increase verbosity"` 30 | Connect string `short:"C" long:"connect" description:"The validator component endpoint to" default:"tcp://localhost:4004"` 31 | Queue uint `long:"max-queue-size" description:"Set the maximum queue size before rejecting process requests" default:"100"` 32 | Threads uint `long:"worker-thread-count" description:"Set the number of worker threads to use for processing requests in parallel" default:"0"` 33 | } 34 | 35 | func main() { 36 | parser := flags.NewParser(&opts, flags.Default) 37 | 38 | logger := logging.Get() 39 | 40 | _, err := parser.Parse() 41 | if err != nil { 42 | if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { 43 | os.Exit(0) 44 | } else { 45 | logger.Error("Failed to parse args: ", err) 46 | os.Exit(2) 47 | } 48 | } 49 | 50 | var loggingLevel int 51 | switch len(opts.Verbose) { 52 | case 0: 53 | loggingLevel = logging.WARN 54 | case 1: 55 | loggingLevel = logging.INFO 56 | default: 57 | loggingLevel = logging.DEBUG 58 | } 59 | logger.SetLevel(loggingLevel) 60 | 61 | logger.Debugf("command line arguments: %v", os.Args) 62 | logger.Debugf("verbose = %v\n", len(opts.Verbose)) 63 | logger.Debugf("endpoint = %v\n", opts.Connect) 64 | 65 | handler := &smallbank.SmallbankHandler{} 66 | processor := processor.NewTransactionProcessor(opts.Connect) 67 | processor.SetMaxQueueSize(opts.Queue) 68 | if opts.Threads > 0 { 69 | processor.SetThreadCount(opts.Threads) 70 | } 71 | processor.AddHandler(handler) 72 | processor.ShutdownOnSignal(syscall.SIGINT, syscall.SIGTERM) 73 | err = processor.Start() 74 | if err != nil { 75 | logger.Error("Processor stopped: ", err) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /examples/xo_go/packaging/systemd/etc/default/sawtooth-xo-tp-go: -------------------------------------------------------------------------------- 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 | #SAWTOOTH_XO_TP_GO_ARGS=-v -C tcp://localhost:4004 17 | -------------------------------------------------------------------------------- /examples/xo_go/packaging/systemd/lib/systemd/system/sawtooth-xo-tp-go.service: -------------------------------------------------------------------------------- 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 | [Unit] 17 | Description=Sawtooth XO TP Go 18 | After=network.target 19 | 20 | [Service] 21 | User=sawtooth 22 | Group=sawtooth 23 | EnvironmentFile=-/etc/default/sawtooth-xo-tp-go 24 | ExecStart=/usr/bin/xo-tp-go $SAWTOOTH_XO_TP_GO_ARGS 25 | Restart=on-failure 26 | 27 | [Install] 28 | WantedBy=multi-user.target 29 | -------------------------------------------------------------------------------- /examples/xo_go/packaging/ubuntu/changelog: -------------------------------------------------------------------------------- 1 | sawtooth-xo-tp-go (@VERSION@) unstable; urgency=low 2 | 3 | * change data here 4 | 5 | -- Hyperledger Sawtooth 6 | -------------------------------------------------------------------------------- /examples/xo_go/packaging/ubuntu/control: -------------------------------------------------------------------------------- 1 | Source: sawtooth-xo-tp-go 2 | Maintainer: Hyperledger Sawtooth 3 | Section: go 4 | Priority: optional 5 | Standards-Version: 3.9.6 6 | Homepage: https://github.com/hyperledger/sawtooth-core 7 | Package: sawtooth-xo-tp-go 8 | Architecture: all 9 | Depends: libssl-dev, libzmq3-dev 10 | Description: Sawtooth Go XO TP 11 | Version: @VERSION@ 12 | -------------------------------------------------------------------------------- /examples/xo_go/packaging/ubuntu/postinst: -------------------------------------------------------------------------------- 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 | set -e 19 | 20 | user="sawtooth" 21 | group="sawtooth" 22 | 23 | if ! getent group $group > /dev/null; then 24 | addgroup --quiet --system $group 25 | fi 26 | 27 | if ! getent passwd $user > /dev/null; then 28 | adduser --quiet --system --ingroup $group $user 29 | fi 30 | -------------------------------------------------------------------------------- /examples/xo_go/src/sawtooth_xo/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 | package main 18 | 19 | import ( 20 | "fmt" 21 | xo "github.com/hyperledger/sawtooth-sdk-go/examples/xo_go/src/sawtooth_xo/handler" 22 | "github.com/hyperledger/sawtooth-sdk-go/logging" 23 | "github.com/hyperledger/sawtooth-sdk-go/processor" 24 | flags "github.com/jessevdk/go-flags" 25 | "os" 26 | "syscall" 27 | ) 28 | 29 | type Opts struct { 30 | Verbose []bool `short:"v" long:"verbose" description:"Increase verbosity"` 31 | Connect string `short:"C" long:"connect" description:"Validator component endpoint to connect to" default:"tcp://localhost:4004"` 32 | } 33 | 34 | func main() { 35 | var opts Opts 36 | 37 | logger := logging.Get() 38 | 39 | parser := flags.NewParser(&opts, flags.Default) 40 | remaining, err := parser.Parse() 41 | if err != nil { 42 | if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { 43 | os.Exit(0) 44 | } else { 45 | logger.Errorf("Failed to parse args: %v", err) 46 | os.Exit(2) 47 | } 48 | } 49 | 50 | if len(remaining) > 0 { 51 | fmt.Printf("Error: Unrecognized arguments passed: %v\n", remaining) 52 | os.Exit(2) 53 | } 54 | 55 | endpoint := opts.Connect 56 | 57 | switch len(opts.Verbose) { 58 | case 2: 59 | logger.SetLevel(logging.DEBUG) 60 | case 1: 61 | logger.SetLevel(logging.INFO) 62 | default: 63 | logger.SetLevel(logging.WARN) 64 | } 65 | 66 | logger.Debugf("command line arguments: %v", os.Args) 67 | logger.Debugf("verbose = %v\n", len(opts.Verbose)) 68 | logger.Debugf("endpoint = %v\n", endpoint) 69 | 70 | handler := &xo.XoHandler{} 71 | processor := processor.NewTransactionProcessor(endpoint) 72 | processor.AddHandler(handler) 73 | processor.ShutdownOnSignal(syscall.SIGINT, syscall.SIGTERM) 74 | err = processor.Start() 75 | if err != nil { 76 | logger.Error("Processor stopped: ", err) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /examples/xo_go/src/sawtooth_xo/xo_payload/xo_payload.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 xo_payload 19 | 20 | import ( 21 | "fmt" 22 | "github.com/hyperledger/sawtooth-sdk-go/processor" 23 | "strconv" 24 | "strings" 25 | ) 26 | 27 | type XoPayload struct { 28 | Name string 29 | Action string 30 | Space int 31 | } 32 | 33 | func FromBytes(payloadData []byte) (*XoPayload, error) { 34 | if payloadData == nil { 35 | return nil, &processor.InvalidTransactionError{Msg: "Must contain payload"} 36 | } 37 | 38 | parts := strings.Split(string(payloadData), ",") 39 | if len(parts) != 3 { 40 | return nil, &processor.InvalidTransactionError{Msg: "Payload is malformed"} 41 | } 42 | 43 | payload := XoPayload{} 44 | payload.Name = parts[0] 45 | payload.Action = parts[1] 46 | 47 | if len(payload.Name) < 1 { 48 | return nil, &processor.InvalidTransactionError{Msg: "Name is required"} 49 | } 50 | 51 | if len(payload.Action) < 1 { 52 | return nil, &processor.InvalidTransactionError{Msg: "Action is required"} 53 | } 54 | 55 | if payload.Action == "take" { 56 | space, err := strconv.Atoi(parts[2]) 57 | if err != nil { 58 | return nil, &processor.InvalidTransactionError{ 59 | Msg: fmt.Sprintf("Invalid Space: '%v'", parts[2])} 60 | } 61 | payload.Space = space 62 | } 63 | 64 | if strings.Contains(payload.Name, "|") { 65 | return nil, &processor.InvalidTransactionError{ 66 | Msg: fmt.Sprintf("Invalid Name (char '|' not allowed): '%v'", parts[2])} 67 | } 68 | 69 | return &payload, nil 70 | } 71 | -------------------------------------------------------------------------------- /examples/xo_go/tests/test_tp_xo_go.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 | xo-tp-go: 21 | build: 22 | context: ../../.. 23 | dockerfile: examples/xo_go/Dockerfile-installed-${DISTRO} 24 | image: sawtooth-xo-tp-go:$ISOLATION_ID 25 | command: xo-tp-go -vv -C tcp://test-xo-tp-go:4004 26 | stop_signal: SIGKILL 27 | 28 | test-xo-tp-go: 29 | image: xo-tests:$ISOLATION_ID 30 | build: 31 | context: ../ 32 | dockerfile: ./xo-tests.dockerfile 33 | image: xo-tests:$ISOLATION_ID 34 | expose: 35 | - 4004 36 | command: nose2-3 37 | -v 38 | -s /data/tests/xo 39 | test_tp_xo 40 | stop_signal: SIGKILL 41 | environment: 42 | TEST_BIND: "tcp://eth0:4004" 43 | PYTHONPATH: "/data/tests/xo/" 44 | -------------------------------------------------------------------------------- /examples/xo_go/tests/test_xo_smoke_go.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 | settings-tp: 21 | image: hyperledger/sawtooth-settings-tp 22 | expose: 23 | - 4004 24 | depends_on: 25 | - validator 26 | command: settings-tp -vv -C tcp://validator:4004 27 | stop_signal: SIGKILL 28 | 29 | xo-tp-go: 30 | image: sawtooth-xo-tp-go:$ISOLATION_ID 31 | build: 32 | context: ../../.. 33 | dockerfile: examples/xo_go/Dockerfile-installed-${DISTRO} 34 | expose: 35 | - 4004 36 | depends_on: 37 | - validator 38 | command: xo-tp-go -vv -C tcp://validator:4004 39 | stop_signal: SIGKILL 40 | 41 | validator: 42 | image: hyperledger/sawtooth-validator 43 | expose: 44 | - 4004 45 | - 8800 46 | - 5050 47 | command: "bash -c \"\ 48 | sawadm keygen && \ 49 | sawset genesis \ 50 | -k /etc/sawtooth/keys/validator.priv \ 51 | -o config-genesis.batch && \ 52 | sawset proposal create \ 53 | -k /etc/sawtooth/keys/validator.priv \ 54 | sawtooth.consensus.algorithm.name=Devmode \ 55 | sawtooth.consensus.algorithm.version=0.1 \ 56 | -o config.batch && \ 57 | sawadm genesis config-genesis.batch config.batch && \ 58 | sawtooth-validator --endpoint tcp://validator:8800 -v \ 59 | --bind component:tcp://eth0:4004 \ 60 | --bind network:tcp://eth0:8800 \ 61 | --bind consensus:tcp://eth0:5050 \ 62 | \"" 63 | stop_signal: SIGKILL 64 | 65 | rest-api: 66 | image: hyperledger/sawtooth-rest-api 67 | expose: 68 | - 8008 69 | depends_on: 70 | - validator 71 | command: sawtooth-rest-api -v --connect tcp://validator:4004 --bind rest-api:8008 72 | stop_signal: SIGKILL 73 | 74 | devmode-rust-engine: 75 | image: hyperledger/sawtooth-devmode-engine-rust 76 | expose: 77 | - 5050 78 | depends_on: 79 | - validator 80 | command: devmode-engine-rust -v --connect tcp://validator:5050 81 | stop_signal: SIGKILL 82 | 83 | test-xo-smoke-go: 84 | image: xo-tests:$ISOLATION_ID 85 | build: 86 | context: ../ 87 | dockerfile: ./xo-tests.dockerfile 88 | expose: 89 | - 8008 90 | depends_on: 91 | - validator 92 | - rest-api 93 | - xo-tp-go 94 | - settings-tp 95 | command: nose2-3 96 | -v 97 | -s /data/tests/xo 98 | test_xo_smoke.TestXoSmoke 99 | stop_signal: SIGKILL 100 | -------------------------------------------------------------------------------- /examples/xo_go/xo-tests.dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | 16 | FROM ubuntu:bionic 17 | 18 | RUN apt-get update \ 19 | && apt-get install gnupg -y 20 | 21 | RUN echo "deb http://repo.sawtooth.me/ubuntu/nightly bionic universe" >> /etc/apt/sources.list 22 | RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA 23 | RUN apt-get update 24 | 25 | RUN apt-get install -y -q \ 26 | python3-sawtooth-cli \ 27 | python3-sawtooth-integration \ 28 | python3-sawtooth-sdk \ 29 | python3-sawtooth-xo-tests 30 | 31 | RUN apt-get install -y -q --allow-downgrades \ 32 | git \ 33 | python3 \ 34 | python3-stdeb 35 | 36 | RUN apt-get install -y -q --allow-downgrades \ 37 | python3-grpcio \ 38 | python3-grpcio-tools \ 39 | python3-protobuf 40 | 41 | RUN apt-get install -y -q --allow-downgrades \ 42 | net-tools \ 43 | python3-cbor \ 44 | python3-colorlog \ 45 | python3-secp256k1 \ 46 | python3-toml \ 47 | python3-yaml \ 48 | python3-zmq 49 | 50 | RUN apt-get install -y -q \ 51 | python3-cov-core \ 52 | python3-nose2 \ 53 | python3-pip 54 | 55 | RUN pip3 install \ 56 | coverage --upgrade 57 | 58 | RUN mkdir -p /var/log/sawtooth 59 | 60 | ENV PATH=$PATH:/project/sawtooth-core/bin 61 | 62 | WORKDIR /project/sawtooth-core 63 | -------------------------------------------------------------------------------- /gen.go: -------------------------------------------------------------------------------- 1 | //go:generate bash gen.sh 2 | 3 | package gen 4 | -------------------------------------------------------------------------------- /gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -f mocks ]; then 4 | rm -rf mocks 5 | fi 6 | 7 | if [ -d protobuf ]; then 8 | rm -rf protobuf 9 | fi 10 | 11 | mkdir -p protobuf mocks/mock_messaging 12 | 13 | # Generate protos 14 | ./protogen 15 | 16 | # Update import paths on generated protos 17 | repourl=github.com/hyperledger/sawtooth-sdk-go 18 | grep -rl '"protobuf/' protobuf/ | while IFS= read -r file; do 19 | sed -i "s|\"protobuf/|\"${repourl}/protobuf/|" "$file" 20 | done 21 | 22 | ( 23 | cd messaging || exit 24 | mockgen -source connection.go >../mocks/mock_messaging/connection.go 25 | ) 26 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/hyperledger/sawtooth-sdk-go 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/brianolson/cbor_go v1.0.0 7 | github.com/btcsuite/btcd v0.22.1 8 | github.com/golang/mock v1.5.0 9 | github.com/golang/protobuf v1.4.3 10 | github.com/jessevdk/go-flags v1.4.0 11 | github.com/pebbe/zmq4 v1.2.5 12 | github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b 13 | google.golang.org/protobuf v1.25.0 14 | gopkg.in/yaml.v2 v2.4.0 15 | ) 16 | -------------------------------------------------------------------------------- /logging/logger.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 logging 19 | 20 | import ( 21 | "fmt" 22 | "io" 23 | "log" 24 | "os" 25 | ) 26 | 27 | const ( 28 | CRITICAL = 50 29 | ERROR = 40 30 | WARN = 30 31 | INFO = 20 32 | DEBUG = 10 33 | ) 34 | 35 | // Set the calldepth so we get the right file when logging 36 | const ( 37 | CALLDEPTH = 3 38 | FLAGS = log.Lshortfile | log.LstdFlags | log.Lmicroseconds 39 | ) 40 | 41 | type Logger struct { 42 | logger *log.Logger 43 | level int 44 | } 45 | 46 | var _LOGGER *Logger = nil 47 | 48 | func Get() *Logger { 49 | if _LOGGER == nil { 50 | _LOGGER = &Logger{ 51 | logger: log.New(os.Stdout, "", FLAGS), 52 | level: DEBUG, 53 | } 54 | } 55 | return _LOGGER 56 | } 57 | 58 | func (self *Logger) SetLevel(level int) { 59 | self.level = level 60 | } 61 | 62 | func (self *Logger) SetOutput(w io.Writer) { 63 | self.logger.SetOutput(w) 64 | } 65 | 66 | func (self *Logger) Debugf(format string, v ...interface{}) { 67 | if self.level <= DEBUG { 68 | self.logf("DEBUG", format, v...) 69 | } 70 | } 71 | 72 | func (self *Logger) Debug(v ...interface{}) { 73 | if self.level <= DEBUG { 74 | self.log("DEBUG", v...) 75 | } 76 | } 77 | 78 | func (self *Logger) Infof(format string, v ...interface{}) { 79 | if self.level <= INFO { 80 | self.logf("INFO", format, v...) 81 | } 82 | } 83 | 84 | func (self *Logger) Info(v ...interface{}) { 85 | if self.level <= INFO { 86 | self.log("INFO", v...) 87 | } 88 | } 89 | 90 | func (self *Logger) Warnf(format string, v ...interface{}) { 91 | if self.level <= WARN { 92 | self.logf("WARN", format, v...) 93 | } 94 | } 95 | 96 | func (self *Logger) Warn(v ...interface{}) { 97 | if self.level <= WARN { 98 | self.log("WARN", v...) 99 | } 100 | } 101 | 102 | func (self *Logger) Errorf(format string, v ...interface{}) { 103 | if self.level <= ERROR { 104 | self.logf("ERROR", format, v...) 105 | } 106 | } 107 | 108 | func (self *Logger) Error(v ...interface{}) { 109 | if self.level <= ERROR { 110 | self.log("ERROR", v...) 111 | } 112 | } 113 | 114 | func (self *Logger) Criticalf(format string, v ...interface{}) { 115 | if self.level <= CRITICAL { 116 | self.logf("CRITICAL", format, v...) 117 | } 118 | } 119 | 120 | func (self *Logger) Critical(v ...interface{}) { 121 | if self.level <= CRITICAL { 122 | self.log("CRITICAL", v...) 123 | } 124 | } 125 | 126 | func (self *Logger) logf(prefix string, format string, v ...interface{}) { 127 | self.logger.Output(CALLDEPTH, "["+prefix+"] "+fmt.Sprintf(format, v...)) 128 | } 129 | 130 | func (self *Logger) log(prefix string, v ...interface{}) { 131 | self.logger.Output(CALLDEPTH, "["+prefix+"] "+fmt.Sprint(v...)) 132 | } 133 | -------------------------------------------------------------------------------- /processor/errors.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 processor 19 | 20 | import "fmt" 21 | 22 | type InvalidTransactionError struct { 23 | Msg string 24 | ExtendedData []byte 25 | } 26 | 27 | // Raised for an Invalid Transaction. 28 | func (err *InvalidTransactionError) Error() string { 29 | return fmt.Sprint("Invalid transaction: ", err.Msg) 30 | } 31 | 32 | type InternalError struct { 33 | Msg string 34 | ExtendedData []byte 35 | } 36 | 37 | // Raised when an internal error occurs during transaction processing. 38 | func (err *InternalError) Error() string { 39 | return fmt.Sprint("Internal error: ", err.Msg) 40 | } 41 | 42 | type AuthorizationException struct { 43 | Msg string 44 | ExtendedData []byte 45 | } 46 | 47 | // Raised when a authorization error occurs. 48 | func (err *AuthorizationException) Error() string { 49 | return fmt.Sprint("Authorization exception: ", err.Msg) 50 | } 51 | -------------------------------------------------------------------------------- /processor/handler.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 processor defines: 19 | // 1. A TransactionHandler interface to be used to create new transaction 20 | // families. 21 | // 22 | // 2. A high-level, general purpose, multi-threaded TransactionProcessor that 23 | // any number of handlers can be added to. 24 | // 25 | // 3. A Context class used to abstract getting and setting addresses in global 26 | // validator state. 27 | package processor 28 | 29 | import ( 30 | "github.com/hyperledger/sawtooth-sdk-go/protobuf/processor_pb2" 31 | ) 32 | 33 | // TransactionHandler is the interface that defines the business logic for a 34 | // new transaction family. This is the only interface that needs to be 35 | // implemented to create a new transaction family. 36 | // 37 | // To create a transaction processor that uses a new transaction handler: 38 | // 39 | // validatorEndpoint := "tcp://localhost:4004" 40 | // myHandler := NewMyHandler() 41 | // processor := NewTransactionProcessor(validatorEndpoint) 42 | // processor.AddHandler(myHandler) 43 | // processor.Start() 44 | // 45 | // The FamilyName(), FamilyVersions(), and Namespaces() methods are 46 | // used by the processor to route processing requests to the handler. 47 | type TransactionHandler interface { 48 | // FamilyName should return the name of the transaction family that this 49 | // handler can process, e.g. "intkey" 50 | FamilyName() string 51 | 52 | // FamilyVersions should return the versions of the transaction 53 | // family that this handler can process. Eg., ["1.0", "1.5"] 54 | FamilyVersions() []string 55 | 56 | // Namespaces should return a slice containing all the handler's 57 | // namespaces, e.g. []string{"abcdef"} 58 | Namespaces() []string 59 | 60 | // Apply is the single method where all the business logic for a 61 | // transaction family is defined. The method will be called by the 62 | // transaction processor upon receiving a TpProcessRequest that the handler 63 | // understands and will pass in the TpProcessRequest and an initialized 64 | // instance of the Context type. 65 | Apply(*processor_pb2.TpProcessRequest, *Context) error 66 | } 67 | -------------------------------------------------------------------------------- /protogen: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright 2018 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 | from glob import glob 19 | import os 20 | import re 21 | import tempfile 22 | from os.path import dirname as DIRNAME 23 | import sys 24 | 25 | from grpc.tools.protoc import main as _protoc 26 | 27 | 28 | JOIN = os.path.join 29 | TOP_DIR = os.path.dirname(os.path.realpath(__file__)) 30 | 31 | 32 | def protoc_go(src_dir, base_dir, pkg): 33 | # 1. Get a list of all .proto files to build 34 | cwd = os.getcwd() 35 | os.chdir(src_dir) 36 | proto_files = glob("*.proto") 37 | os.chdir(cwd) 38 | # 2. Create a temp directory for building 39 | with tempfile.TemporaryDirectory() as tmp_dir: 40 | defer = [] 41 | # 3. In order to have each protobuf file in its own namespace, 42 | # directories need to be created for all of them and the .proto file 43 | # copied in 44 | for proto_file in proto_files: 45 | proto = proto_file[:-6] 46 | sub_pkg = JOIN(pkg, proto) 47 | tmp_pkg_dir = JOIN(tmp_dir, sub_pkg + "_pb2") 48 | os.makedirs(tmp_pkg_dir) 49 | src = JOIN(src_dir, proto_file) 50 | dst = JOIN(tmp_pkg_dir, proto_file) 51 | with open(src, encoding='utf-8') as fin: 52 | with open(dst, "w", encoding='utf-8') as fout: 53 | src_contents = fin.read() 54 | fixed_contents = fix_import(src_contents, pkg, sub_dir=True) 55 | fout.write(fixed_contents) 56 | # Need to defer until the whole directory is setup 57 | defer.append([ 58 | __file__, 59 | "-I=%s" % tmp_dir, 60 | "--go_out=%s" % JOIN(TOP_DIR, base_dir), 61 | "%s" % dst 62 | ]) 63 | for args in defer: 64 | _protoc(args) 65 | 66 | 67 | def fix_import(contents, pkg, sub_dir=False): 68 | pattern = r'^import "(.*)\.proto\"' 69 | if sub_dir: 70 | template = r'import "%s/\1_pb2/\1.proto"' 71 | else: 72 | template = r'import "%s/\1.proto"' 73 | return re.sub( 74 | pattern, 75 | lambda match: match.expand(template) % pkg, 76 | contents, 77 | flags=re.MULTILINE) 78 | 79 | 80 | def main(): 81 | protoc_go("protos", "./", "protobuf") 82 | protoc_go("examples/smallbank/protos", 83 | "examples/smallbank/smallbank_go/src", 84 | "protobuf") 85 | 86 | 87 | if __name__ == "__main__": 88 | try: 89 | main() 90 | except KeyboardInterrupt: 91 | exit(1) 92 | -------------------------------------------------------------------------------- /protos/authorization.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 | option java_multiple_files = true; 18 | option java_package = "sawtooth.sdk.protobuf"; 19 | option go_package = "protobuf/authorization_pb2"; 20 | 21 | message ConnectionRequest { 22 | // This is the first message that must be sent to start off authorization. 23 | // The endpoint of the connection. 24 | string endpoint = 1; 25 | } 26 | 27 | enum RoleType { 28 | ROLE_TYPE_UNSET = 0; 29 | 30 | // A shorthand request for asking for all allowed roles. 31 | ALL = 1; 32 | 33 | // Role defining validator to validator communication 34 | NETWORK = 2; 35 | } 36 | 37 | message ConnectionResponse { 38 | // Whether the connection can participate in authorization 39 | enum Status { 40 | STATUS_UNSET = 0; 41 | OK = 1; 42 | ERROR = 2; 43 | } 44 | 45 | //Authorization Type required for the authorization procedure 46 | enum AuthorizationType { 47 | AUTHORIZATION_TYPE_UNSET = 0; 48 | TRUST = 1; 49 | CHALLENGE = 2; 50 | } 51 | 52 | message RoleEntry { 53 | // The role type for this role entry 54 | RoleType role = 1; 55 | 56 | // The Authorization Type required for the above role 57 | AuthorizationType auth_type = 2; 58 | } 59 | 60 | repeated RoleEntry roles = 1; 61 | Status status = 2; 62 | } 63 | 64 | message AuthorizationTrustRequest { 65 | // A set of requested RoleTypes 66 | repeated RoleType roles = 1; 67 | string public_key = 2; 68 | } 69 | 70 | message AuthorizationTrustResponse { 71 | // The actual set the requester has access to 72 | repeated RoleType roles = 1; 73 | } 74 | 75 | message AuthorizationViolation { 76 | // The Role the requester did not have access to 77 | RoleType violation = 1; 78 | } 79 | 80 | message AuthorizationChallengeRequest { 81 | // Empty message sent to request a payload to sign 82 | } 83 | 84 | message AuthorizationChallengeResponse { 85 | // Random payload that the connecting node must sign 86 | bytes payload = 1; 87 | } 88 | 89 | message AuthorizationChallengeSubmit { 90 | // public key of node 91 | string public_key = 1; 92 | 93 | // signature derived from signing the challenge payload 94 | string signature = 3; 95 | 96 | // A set of requested Roles 97 | repeated RoleType roles = 4; 98 | } 99 | 100 | message AuthorizationChallengeResult { 101 | // The approved roles for that connection 102 | repeated RoleType roles = 1; 103 | } 104 | -------------------------------------------------------------------------------- /protos/batch.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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.sdk.protobuf"; 20 | option go_package = "protobuf/batch_pb2"; 21 | 22 | import "transaction.proto"; 23 | 24 | message BatchHeader { 25 | // Public key for the client that signed the BatchHeader 26 | string signer_public_key = 1; 27 | 28 | // List of transaction.header_signatures that match the order of 29 | // transactions required for the batch 30 | repeated string transaction_ids = 2; 31 | } 32 | 33 | message Batch { 34 | // The serialized version of the BatchHeader 35 | bytes header = 1; 36 | 37 | // The signature derived from signing the header 38 | string header_signature = 2; 39 | 40 | // A list of the transactions that match the list of 41 | // transaction_ids listed in the batch header 42 | repeated Transaction transactions = 3; 43 | 44 | // A debugging flag which indicates this batch should be traced through the 45 | // system, resulting in a higher level of debugging output. 46 | bool trace = 4; 47 | } 48 | 49 | message BatchList { 50 | repeated Batch batches = 1; 51 | } 52 | -------------------------------------------------------------------------------- /protos/block.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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 | option java_multiple_files = true; 18 | option java_package = "sawtooth.sdk.protobuf"; 19 | option go_package = "./block_pb2"; 20 | 21 | import "batch.proto"; 22 | 23 | message BlockHeader { 24 | // Block number in the chain 25 | uint64 block_num = 1; 26 | 27 | // The header_signature of the previous block that was added to the chain. 28 | string previous_block_id = 2; 29 | 30 | // Public key for the component internal to the validator that 31 | // signed the BlockHeader 32 | string signer_public_key = 3; 33 | 34 | // List of batch.header_signatures that match the order of batches 35 | // required for the block 36 | repeated string batch_ids = 4; 37 | 38 | // Bytes that are set and verified by the consensus algorithm used to 39 | // create and validate the block 40 | bytes consensus = 5; 41 | 42 | // The state_root_hash should match the final state_root after all 43 | // transactions in the batches have been applied, otherwise the block 44 | // is not valid 45 | string state_root_hash = 6; 46 | } 47 | 48 | message Block { 49 | // The serialized version of the BlockHeader 50 | bytes header = 1; 51 | 52 | // The signature derived from signing the header 53 | string header_signature = 2; 54 | 55 | // A list of batches. The batches may contain new batches that other 56 | // validators may not have received yet, or they will be all batches needed 57 | // for block validation when passed to the journal 58 | repeated Batch batches = 3; 59 | } 60 | -------------------------------------------------------------------------------- /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 = "protobuf/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 | -------------------------------------------------------------------------------- /protos/client_batch.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_batch_pb2"; 21 | 22 | import "batch.proto"; 23 | import "client_list_control.proto"; 24 | 25 | 26 | // A request to return a list of batches from the validator. May include the id 27 | // of a particular block to be the `head` of the chain being requested. In that 28 | // case the list will include the batches from that block, and all batches 29 | // previous to that block on the chain. Filter with specific `batch_ids`. 30 | message ClientBatchListRequest { 31 | string head_id = 1; 32 | repeated string batch_ids = 2; 33 | ClientPagingControls paging = 3; 34 | repeated ClientSortControls sorting = 4; 35 | } 36 | 37 | // A response that lists batches from newest to oldest. 38 | // 39 | // Statuses: 40 | // * OK - everything worked as expected 41 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 42 | // * NOT_READY - the validator does not yet have a genesis block 43 | // * NO_ROOT - the head block specified was not found 44 | // * NO_RESOURCE - no batches were found with the parameters specified 45 | // * INVALID_PAGING - the paging controls were malformed or out of range 46 | // * INVALID_SORT - the sorting controls were malformed or invalid 47 | message ClientBatchListResponse { 48 | enum Status { 49 | STATUS_UNSET = 0; 50 | OK = 1; 51 | INTERNAL_ERROR = 2; 52 | NOT_READY = 3; 53 | NO_ROOT = 4; 54 | NO_RESOURCE = 5; 55 | INVALID_PAGING = 6; 56 | INVALID_SORT = 7; 57 | INVALID_ID = 8; 58 | } 59 | Status status = 1; 60 | repeated Batch batches = 2; 61 | string head_id = 3; 62 | ClientPagingResponse paging = 4; 63 | } 64 | 65 | // Fetches a specific batch by its id (header_signature) from the blockchain. 66 | message ClientBatchGetRequest { 67 | string batch_id = 1; 68 | } 69 | 70 | // A response that returns the batch specified by a ClientBatchGetRequest. 71 | // 72 | // Statuses: 73 | // * OK - everything worked as expected, batch has been fetched 74 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 75 | // * NO_RESOURCE - no batch with the specified id exists 76 | message ClientBatchGetResponse { 77 | enum Status { 78 | STATUS_UNSET = 0; 79 | OK = 1; 80 | INTERNAL_ERROR = 2; 81 | NO_RESOURCE = 5; 82 | INVALID_ID = 8; 83 | } 84 | Status status = 1; 85 | Batch batch = 2; 86 | } 87 | -------------------------------------------------------------------------------- /protos/client_batch_submit.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_batch_submit_pb2"; 21 | 22 | import "batch.proto"; 23 | 24 | 25 | // Information about the status of a batch submitted to the validator. 26 | // 27 | // Attributes: 28 | // batch_id: The id (header_signature) of the batch 29 | // status: The committed status of the batch 30 | // invalid_transactions: Info for transactions that failed, if any 31 | // 32 | // Statuses: 33 | // COMMITTED - the batch was accepted and has been committed to the chain 34 | // INVALID - the batch failed validation, it should be resubmitted 35 | // PENDING - the batch is still being processed 36 | // UNKNOWN - no status for the batch could be found (possibly invalid) 37 | message ClientBatchStatus { 38 | enum Status { 39 | STATUS_UNSET = 0; 40 | COMMITTED = 1; 41 | INVALID = 2; 42 | PENDING = 3; 43 | UNKNOWN = 4; 44 | } 45 | message InvalidTransaction { 46 | string transaction_id = 1; 47 | string message = 2; 48 | bytes extended_data = 3; 49 | } 50 | string batch_id = 1; 51 | Status status = 2; 52 | repeated InvalidTransaction invalid_transactions = 3; 53 | } 54 | 55 | // Submits a list of Batches to be added to the blockchain. 56 | message ClientBatchSubmitRequest { 57 | repeated Batch batches = 1; 58 | } 59 | 60 | // This is a response to a submission of one or more Batches. 61 | // Statuses: 62 | // * OK - everything with the request worked as expected 63 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 64 | // * INVALID_BATCH - the batch failed validation, likely due to a bad signature 65 | // * QUEUE_FULL - the batch is unable to be queued for processing, due to 66 | // a full processing queue. The batch may be submitted again. 67 | message ClientBatchSubmitResponse { 68 | enum Status { 69 | STATUS_UNSET = 0; 70 | OK = 1; 71 | INTERNAL_ERROR = 2; 72 | INVALID_BATCH = 3; 73 | QUEUE_FULL = 4; 74 | } 75 | Status status = 1; 76 | } 77 | 78 | // A request for the status of one or more batches, specified by id. 79 | // If `wait` is set to true, the validator will wait to respond until all 80 | // batches are committed, or until the specified `timeout` in seconds has 81 | // elapsed. Defaults to 300. 82 | message ClientBatchStatusRequest { 83 | repeated string batch_ids = 1; 84 | bool wait = 2; 85 | uint32 timeout = 3; 86 | } 87 | 88 | // This is a response to a request for the status of specific batches. 89 | // Statuses: 90 | // * OK - everything with the request worked as expected 91 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 92 | // * NO_RESOURCE - the response contains no data, likely because 93 | // no ids were specified in the request 94 | message ClientBatchStatusResponse { 95 | enum Status { 96 | STATUS_UNSET = 0; 97 | OK = 1; 98 | INTERNAL_ERROR = 2; 99 | NO_RESOURCE = 5; 100 | INVALID_ID = 8; 101 | } 102 | Status status = 1; 103 | repeated ClientBatchStatus batch_statuses = 2; 104 | } 105 | -------------------------------------------------------------------------------- /protos/client_block.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_block_pb2"; 21 | 22 | import "block.proto"; 23 | import "client_list_control.proto"; 24 | 25 | 26 | // A request to return a list of blocks from the validator. May include the id 27 | // of a particular block to be the `head` of the chain being requested. In that 28 | // case the list will include that block (if found), and all blocks previous 29 | // to it on the chain. Can be filtered using specific `block_ids`. 30 | message ClientBlockListRequest { 31 | string head_id = 1; 32 | repeated string block_ids = 2; 33 | ClientPagingControls paging = 3; 34 | repeated ClientSortControls sorting = 4; 35 | } 36 | 37 | // A response that lists a chain of blocks with the newest at the beginning, 38 | // and the oldest (genesis) block at the end. 39 | // 40 | // Statuses: 41 | // * OK - everything worked as expected 42 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 43 | // * NOT_READY - the validator does not yet have a genesis block 44 | // * NO_ROOT - the head block specified was not found 45 | // * NO_RESOURCE - no blocks were found with the parameters specified 46 | // * INVALID_PAGING - the paging controls were malformed or out of range 47 | // * INVALID_SORT - the sorting controls were malformed or invalid 48 | message ClientBlockListResponse { 49 | enum Status { 50 | STATUS_UNSET = 0; 51 | OK = 1; 52 | INTERNAL_ERROR = 2; 53 | NOT_READY = 3; 54 | NO_ROOT = 4; 55 | NO_RESOURCE = 5; 56 | INVALID_PAGING = 6; 57 | INVALID_SORT = 7; 58 | INVALID_ID = 8; 59 | } 60 | Status status = 1; 61 | repeated Block blocks = 2; 62 | string head_id = 3; 63 | ClientPagingResponse paging = 4; 64 | } 65 | 66 | // A request to return a specific block from the validator. The block must be 67 | // specified by its unique id, in this case the block's header signature 68 | message ClientBlockGetByIdRequest { 69 | string block_id = 1; 70 | } 71 | 72 | // A request to return a specific block from the validator. The block must be 73 | // specified by its block number 74 | message ClientBlockGetByNumRequest { 75 | uint64 block_num = 1; 76 | } 77 | 78 | // A request to return a specific block from the validator. The block 79 | // containing the given transaction is returned. If no block on the current 80 | // chain contains the transaction, NO_RESOURCE is returned. 81 | message ClientBlockGetByTransactionIdRequest { 82 | string transaction_id = 1; 83 | } 84 | 85 | // A request to return a specific block from the validator. The block 86 | // containing the given batch is returned. If no block on the current chain 87 | // contains the batch, NO_RESOURCE is returned. 88 | message ClientBlockGetByBatchIdRequest { 89 | string batch_id = 1; 90 | } 91 | 92 | // A response that returns the block specified by a ClientBlockGetByIdRequest 93 | // or ClientBlockGetByNumRequest. 94 | // 95 | // Statuses: 96 | // * OK - everything worked as expected 97 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 98 | // * NO_RESOURCE - no block with the specified id exists 99 | message ClientBlockGetResponse { 100 | enum Status { 101 | STATUS_UNSET = 0; 102 | OK = 1; 103 | INTERNAL_ERROR = 2; 104 | NO_RESOURCE = 5; 105 | INVALID_ID = 8; 106 | } 107 | Status status = 1; 108 | Block block = 2; 109 | } 110 | -------------------------------------------------------------------------------- /protos/client_event.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_event_pb2"; 21 | 22 | import "events.proto"; 23 | 24 | 25 | message ClientEventsSubscribeRequest { 26 | repeated EventSubscription subscriptions = 1; 27 | // The block id (or ids, if trying to walk back a fork) the subscriber last 28 | // received events on. It can be set to empty if it has not yet received the 29 | // genesis block. 30 | repeated string last_known_block_ids = 2; 31 | } 32 | 33 | message ClientEventsSubscribeResponse { 34 | enum Status { 35 | STATUS_UNSET = 0; 36 | OK = 1; 37 | INVALID_FILTER = 2; 38 | UNKNOWN_BLOCK = 3; 39 | } 40 | Status status = 1; 41 | // Additional information about the response status 42 | string response_message = 2; 43 | } 44 | 45 | message ClientEventsUnsubscribeRequest {} 46 | 47 | message ClientEventsUnsubscribeResponse { 48 | enum Status { 49 | STATUS_UNSET = 0; 50 | OK = 1; 51 | INTERNAL_ERROR = 2; 52 | } 53 | Status status = 1; 54 | } 55 | 56 | message ClientEventsGetRequest { 57 | repeated EventSubscription subscriptions = 1; 58 | repeated string block_ids = 2; 59 | } 60 | 61 | message ClientEventsGetResponse { 62 | enum Status { 63 | STATUS_UNSET = 0; 64 | OK = 1; 65 | INTERNAL_ERROR = 2; 66 | INVALID_FILTER = 3; 67 | UNKNOWN_BLOCK = 4; 68 | } 69 | Status status = 1; 70 | repeated Event events = 2; 71 | 72 | } 73 | -------------------------------------------------------------------------------- /protos/client_list_control.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_list_control_pb2"; 21 | 22 | // Paging controls to be sent with List requests. 23 | // Attributes: 24 | // start: The id of a resource to start the page with 25 | // limit: The number of results per page, defaults to 100 and maxes out at 1000 26 | message ClientPagingControls { 27 | string start = 1; 28 | int32 limit = 2; 29 | } 30 | 31 | // Information about the pagination used, sent back with List responses. 32 | // Attributes: 33 | // next: The id of the first resource in the next page 34 | // start: The id of the first resource in the returned page 35 | // limit: The number of results per page, defaults to 100 and maxes out at 1000 36 | message ClientPagingResponse { 37 | string next = 1; 38 | string start = 2; 39 | int32 limit = 3; 40 | 41 | } 42 | 43 | // Sorting controls to be sent with List requests. More than one can be sent. 44 | // If so, the first is used, and additional controls are tie-breakers. 45 | // Attributes: 46 | // keys: Nested set of keys to sort by (i.e. ['default, block_num']) 47 | // reverse: Whether or not to reverse the sort (i.e. descending order) 48 | message ClientSortControls { 49 | repeated string keys = 1; 50 | bool reverse = 2; 51 | } 52 | -------------------------------------------------------------------------------- /protos/client_peers.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_peer"; 21 | 22 | message ClientPeersGetRequest{ 23 | } 24 | 25 | message ClientPeersGetResponse { 26 | enum Status { 27 | STATUS_UNSET = 0; 28 | OK = 1; 29 | ERROR = 2; 30 | } 31 | Status status = 1; 32 | repeated string peers = 2; 33 | } 34 | -------------------------------------------------------------------------------- /protos/client_receipt.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_receipt_pb2"; 21 | 22 | import "transaction_receipt.proto"; 23 | 24 | // Fetches a specific txn by its id (header_signature) from the blockchain. 25 | message ClientReceiptGetRequest { 26 | repeated string transaction_ids = 1; 27 | } 28 | 29 | // A response that returns the txn receipt specified by a 30 | // ClientTransactionReceiptGetRequest. 31 | // 32 | // Statuses: 33 | // * OK - everything worked as expected, txn receipt has been fetched 34 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 35 | // * NO_RESOURCE - no receipt exists for the transaction id specified 36 | message ClientReceiptGetResponse { 37 | enum Status { 38 | STATUS_UNSET = 0; 39 | OK = 1; 40 | INTERNAL_ERROR = 2; 41 | NO_RESOURCE = 5; 42 | INVALID_ID = 8; 43 | } 44 | Status status = 1; 45 | repeated TransactionReceipt receipts = 2; 46 | } 47 | -------------------------------------------------------------------------------- /protos/client_state.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_state_pb2"; 21 | 22 | import "client_list_control.proto"; 23 | 24 | 25 | // A request to list every entry in global state. Defaults to the most current 26 | // tree, but can fetch older state by specifying a state root. Results can be 27 | // further filtered by specifying a subtree with a partial address. 28 | message ClientStateListRequest { 29 | string state_root = 1; 30 | string address = 3; 31 | ClientPagingControls paging = 4; 32 | repeated ClientSortControls sorting = 5; 33 | } 34 | 35 | // A response that lists the data Entries from global state, filtered by state 36 | // root or subtree address according to the request. Returns the state root 37 | // used to facilitate future requests. 38 | // 39 | // Statuses: 40 | // * OK - everything worked as expected 41 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 42 | // * NOT_READY - the validator does not yet have a genesis block 43 | // * NO_ROOT - the head block or merkle_root specified was not found 44 | // * NO_RESOURCE - the head/root specified is valid, but contains no data 45 | // * INVALID_PAGING - the paging controls were malformed or out of range 46 | // * INVALID_SORT - the sorting controls were malformed or invalid 47 | 48 | message ClientStateListResponse { 49 | enum Status { 50 | STATUS_UNSET = 0; 51 | OK = 1; 52 | INTERNAL_ERROR = 2; 53 | NOT_READY = 3; 54 | NO_ROOT = 4; 55 | NO_RESOURCE = 5; 56 | INVALID_PAGING = 6; 57 | INVALID_SORT = 7; 58 | INVALID_ADDRESS = 8; 59 | INVALID_ROOT = 9; 60 | } 61 | 62 | // An entry in the State 63 | message Entry { 64 | string address = 1; 65 | bytes data = 2; 66 | } 67 | 68 | Status status = 1; 69 | repeated Entry entries = 2; 70 | string state_root = 3; 71 | ClientPagingResponse paging = 4; 72 | } 73 | 74 | // A request from a client for a particular entry in global state. 75 | // Like State List, it defaults to the newest state, but a state root 76 | // can be used to specify older data. Unlike State List the request must be 77 | // provided with a full address that corresponds to a single entry. 78 | message ClientStateGetRequest { 79 | string state_root = 1; 80 | string address = 3; 81 | } 82 | 83 | // The response to a State Get Request from the client. Sends back just 84 | // the data stored at the entry, not the address. Also sends back the 85 | // head block id used to facilitate further requests. 86 | // 87 | // Statuses: 88 | // * OK - everything worked as expected 89 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 90 | // * NOT_READY - the validator does not yet have a genesis block 91 | // * NO_ROOT - the state_root specified was not found 92 | // * NO_RESOURCE - the address specified doesn't exist 93 | // * INVALID_ADDRESS - address isn't a valid, i.e. it's a subtree (truncated) 94 | message ClientStateGetResponse { 95 | enum Status { 96 | STATUS_UNSET = 0; 97 | OK = 1; 98 | INTERNAL_ERROR = 2; 99 | NOT_READY = 3; 100 | NO_ROOT = 4; 101 | NO_RESOURCE = 5; 102 | INVALID_ADDRESS = 6; 103 | INVALID_ROOT = 7; 104 | } 105 | Status status = 1; 106 | bytes value = 2; 107 | string state_root = 3; 108 | } 109 | -------------------------------------------------------------------------------- /protos/client_status.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_status"; 21 | 22 | // A request to get miscellaneous information about the validator 23 | message ClientStatusGetRequest{ 24 | } 25 | 26 | message ClientStatusGetResponse { 27 | // The status of the response message, not the validator's status 28 | enum Status { 29 | STATUS_UNSET = 0; 30 | OK = 1; 31 | ERROR = 2; 32 | } 33 | 34 | // Information about the validator's peers 35 | message Peer { 36 | // The peer's public network endpoint 37 | string endpoint = 1; 38 | } 39 | 40 | Status status = 1; 41 | repeated Peer peers = 2; 42 | // The validator's public network endpoint 43 | string endpoint = 3; 44 | } 45 | -------------------------------------------------------------------------------- /protos/client_transaction.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.sdk.protobuf"; 20 | option go_package = "protobuf/client_transaction_pb2"; 21 | 22 | import "transaction.proto"; 23 | import "client_list_control.proto"; 24 | 25 | 26 | // A request to return a list of txns from the validator. May include the id 27 | // of a particular block to be the `head` of the chain being requested. In that 28 | // case the list will include the txns from that block, and all txns 29 | // previous to that block on the chain. Filter with specific `transaction_ids`. 30 | message ClientTransactionListRequest { 31 | string head_id = 1; 32 | repeated string transaction_ids = 2; 33 | ClientPagingControls paging = 3; 34 | repeated ClientSortControls sorting = 4; 35 | } 36 | 37 | // A response that lists transactions from newest to oldest. 38 | // 39 | // Statuses: 40 | // * OK - everything worked as expected 41 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 42 | // * NOT_READY - the validator does not yet have a genesis block 43 | // * NO_ROOT - the head block specified was not found 44 | // * NO_RESOURCE - no txns were found with the parameters specified 45 | // * INVALID_PAGING - the paging controls were malformed or out of range 46 | // * INVALID_SORT - the sorting controls were malformed or invalid 47 | message ClientTransactionListResponse { 48 | enum Status { 49 | STATUS_UNSET = 0; 50 | OK = 1; 51 | INTERNAL_ERROR = 2; 52 | NOT_READY = 3; 53 | NO_ROOT = 4; 54 | NO_RESOURCE = 5; 55 | INVALID_PAGING = 6; 56 | INVALID_SORT = 7; 57 | INVALID_ID = 8; 58 | } 59 | Status status = 1; 60 | repeated Transaction transactions = 2; 61 | string head_id = 3; 62 | ClientPagingResponse paging = 4; 63 | } 64 | 65 | // Fetches a specific txn by its id (header_signature) from the blockchain. 66 | message ClientTransactionGetRequest { 67 | string transaction_id = 1; 68 | } 69 | 70 | // A response that returns the txn specified by a ClientTransactionGetRequest. 71 | // 72 | // Statuses: 73 | // * OK - everything worked as expected, txn has been fetched 74 | // * INTERNAL_ERROR - general error, such as protobuf failing to deserialize 75 | // * NO_RESOURCE - no txn with the specified id exists 76 | message ClientTransactionGetResponse { 77 | enum Status { 78 | STATUS_UNSET = 0; 79 | OK = 1; 80 | INTERNAL_ERROR = 2; 81 | NO_RESOURCE = 5; 82 | INVALID_ID = 8; 83 | } 84 | Status status = 1; 85 | Transaction transaction = 2; 86 | } 87 | -------------------------------------------------------------------------------- /protos/events.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.sdk.protobuf"; 20 | option go_package = "protobuf/events_pb2"; 21 | 22 | 23 | message Event { 24 | // Used to subscribe to events and servers as a hint for how to deserialize 25 | // event_data and what pairs to expect in attributes. 26 | string event_type = 1; 27 | 28 | // Transparent data defined by the event_type. 29 | message Attribute { 30 | string key = 1; 31 | string value = 2; 32 | } 33 | repeated Attribute attributes = 2; 34 | 35 | // Opaque data defined by the event_type. 36 | bytes data = 3; 37 | } 38 | 39 | message EventList { 40 | repeated Event events = 1; 41 | } 42 | 43 | message EventFilter { 44 | // EventFilter is used when subscribing to events to limit the events 45 | // received within a given event type. See 46 | // validator/server/events/subscription.py for further explanation. 47 | string key = 1; 48 | string match_string = 2; 49 | 50 | enum FilterType { 51 | FILTER_TYPE_UNSET = 0; 52 | SIMPLE_ANY = 1; 53 | SIMPLE_ALL = 2; 54 | REGEX_ANY = 3; 55 | REGEX_ALL = 4; 56 | } 57 | FilterType filter_type = 3; 58 | } 59 | 60 | message EventSubscription { 61 | // EventSubscription is used when subscribing to events to specify the type 62 | // of events being subscribed to, along with any additional filters. See 63 | // validator/server/events/subscription.py for further explanation. 64 | string event_type = 1; 65 | repeated EventFilter filters = 2; 66 | } 67 | -------------------------------------------------------------------------------- /protos/genesis.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.sdk.protobuf"; 20 | option go_package = "protobuf/genesis_pb2"; 21 | 22 | import "batch.proto"; 23 | 24 | message GenesisData { 25 | // The list of batches that will be applied during the genesis process 26 | repeated Batch batches = 1; 27 | } 28 | -------------------------------------------------------------------------------- /protos/identity.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.identity.protobuf"; 20 | option go_package = "protobuf/identity_pb2"; 21 | 22 | message Policy { 23 | 24 | enum EntryType { 25 | ENTRY_TYPE_UNSET = 0; 26 | PERMIT_KEY = 1; 27 | DENY_KEY = 2; 28 | } 29 | 30 | message Entry { 31 | // Whether this is a Permit_KEY or Deny_KEY entry 32 | EntryType type = 1; 33 | 34 | // This should be a public key or * to refer to all participants. 35 | string key = 2; 36 | } 37 | 38 | // name of the policy, this should be unique. 39 | string name = 1; 40 | 41 | // list of Entries 42 | // The entries will be processed in order from first to last. 43 | repeated Entry entries = 2; 44 | } 45 | 46 | // Policy will be stored in a Policy list to account for state collisions 47 | message PolicyList { 48 | repeated Policy policies = 1; 49 | } 50 | 51 | 52 | message Role { 53 | // Role name 54 | string name = 1; 55 | 56 | // Name of corresponding policy 57 | string policy_name = 2; 58 | } 59 | 60 | // Roles will be stored in a RoleList to account for state collisions 61 | message RoleList { 62 | repeated Role roles = 1; 63 | } 64 | -------------------------------------------------------------------------------- /protos/merkle.proto: -------------------------------------------------------------------------------- 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 | syntax = "proto3"; 16 | 17 | option java_multiple_files = true; 18 | option java_package = "sawtooth.sdk.protobuf"; 19 | option go_package = "protobuf/merkle_pb2"; 20 | 21 | // An Entry in the change log for a given state root. 22 | message ChangeLogEntry { 23 | // A state root that succeed this root. 24 | message Successor { 25 | // A root hash of a merkle trie based of off this root. 26 | bytes successor = 1; 27 | 28 | // The keys (i.e. hashes) that were replaced (i.e. deleted) by this 29 | // successor. These may be deleted during pruning. 30 | repeated bytes deletions = 2; 31 | } 32 | 33 | // A root hash of a merkle trie this tree was based off. 34 | bytes parent = 1; 35 | 36 | // The hashes that were added for this root. These may be deleted during 37 | // pruning, if this root is being abandoned. 38 | repeated bytes additions = 2; 39 | 40 | // The list of successors. 41 | repeated Successor successors = 3; 42 | } 43 | -------------------------------------------------------------------------------- /protos/network.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016, 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 | option java_multiple_files = true; 18 | option java_package = "sawtooth.sdk.protobuf"; 19 | option go_package = "protobuf/network_pb2"; 20 | 21 | // The disconnect message from a client to the server 22 | message DisconnectMessage { 23 | } 24 | 25 | // The registration request from a peer to the validator 26 | message PeerRegisterRequest { 27 | string endpoint = 1; 28 | // The current version of the network protocol that is being used by the 29 | // sender. This version is an increasing value. 30 | uint32 protocol_version = 2; 31 | } 32 | 33 | // The unregistration request from a peer to the validator 34 | message PeerUnregisterRequest { 35 | } 36 | 37 | message GetPeersRequest { 38 | } 39 | 40 | message GetPeersResponse { 41 | repeated string peer_endpoints = 1; 42 | } 43 | 44 | message PingRequest { 45 | } 46 | 47 | message PingResponse{ 48 | } 49 | 50 | message GossipMessage { 51 | enum ContentType{ 52 | CONTENT_TYPE_UNSET = 0; 53 | BLOCK = 1; 54 | BATCH = 2; 55 | CONSENSUS = 3; 56 | } 57 | bytes content = 1; 58 | ContentType content_type = 2; 59 | uint32 time_to_live = 3; 60 | } 61 | 62 | // A response sent from the validator to the peer acknowledging message 63 | // receipt 64 | message NetworkAcknowledgement { 65 | enum Status { 66 | STATUS_UNSET = 0; 67 | OK = 1; 68 | ERROR = 2; 69 | } 70 | 71 | Status status = 1; 72 | } 73 | 74 | message GossipBlockRequest { 75 | // The id of the block that is being requested 76 | string block_id = 1; 77 | 78 | // A random string that provides uniqueness for requests with 79 | // otherwise identical fields. 80 | string nonce = 2; 81 | uint32 time_to_live = 3; 82 | 83 | } 84 | 85 | message GossipBlockResponse { 86 | // The block 87 | bytes content = 1; 88 | } 89 | 90 | message GossipBatchResponse { 91 | //The batch 92 | bytes content = 1; 93 | } 94 | 95 | message GossipBatchByBatchIdRequest { 96 | // The id of the batch that is being requested 97 | string id = 1; 98 | 99 | // A random string that provides uniqueness for requests with 100 | // otherwise identical fields. 101 | string nonce = 2; 102 | uint32 time_to_live = 3; 103 | 104 | } 105 | 106 | message GossipBatchByTransactionIdRequest { 107 | // The id's of the transaction that are in the batches requested 108 | repeated string ids = 1; 109 | 110 | // A random string that provides uniqueness for requests with 111 | // otherwise identical fields. 112 | string nonce = 2; 113 | uint32 time_to_live = 3; 114 | 115 | } 116 | -------------------------------------------------------------------------------- /protos/processor.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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 | option java_multiple_files = true; 18 | option java_package = "sawtooth.sdk.protobuf"; 19 | option go_package = "protobuf/processor_pb2"; 20 | 21 | import "transaction.proto"; 22 | 23 | 24 | // The registration request from the transaction processor to the 25 | // validator/executor 26 | message TpRegisterRequest { 27 | 28 | // A settled upon name for the capabilities of the transaction processor. 29 | // For example: intkey, xo 30 | string family = 1; 31 | 32 | // The version supported. For example: 33 | // 1.0 for version 1.0 34 | // 2.1 for version 2.1 35 | string version = 2; 36 | 37 | // The namespaces this transaction processor expects to interact with 38 | // when processing transactions matching this specification; will be 39 | // enforced by the state API on the validator. 40 | repeated string namespaces = 4; 41 | 42 | // The maximum number of transactions that this transaction processor can 43 | // handle at once. 44 | uint32 max_occupancy = 5; 45 | } 46 | 47 | // A response sent from the validator to the transaction processor 48 | // acknowledging the registration 49 | message TpRegisterResponse { 50 | enum Status { 51 | STATUS_UNSET = 0; 52 | OK = 1; 53 | ERROR = 2; 54 | } 55 | 56 | Status status = 1; 57 | } 58 | 59 | // The unregistration request from the transaction processor to the 60 | // validator/executor. The correct handlers are determined from the 61 | // zeromq identity of the tp, on the validator side. 62 | message TpUnregisterRequest { 63 | 64 | } 65 | 66 | // A response sent from the validator to the transaction processor 67 | // acknowledging the unregistration 68 | message TpUnregisterResponse { 69 | enum Status { 70 | STATUS_UNSET = 0; 71 | OK = 1; 72 | ERROR = 2; 73 | } 74 | 75 | Status status = 1; 76 | } 77 | 78 | 79 | // The request from the validator/executor of the transaction processor 80 | // to verify a transaction. 81 | message TpProcessRequest { 82 | TransactionHeader header = 1; // The transaction header 83 | bytes payload = 2; // The transaction payload 84 | string signature = 3; // The transaction header_signature 85 | string context_id = 4; // The context_id for state requests. 86 | } 87 | 88 | 89 | // The response from the transaction processor to the validator/executor 90 | // used to respond about the validity of a transaction 91 | message TpProcessResponse { 92 | enum Status { 93 | STATUS_UNSET = 0; 94 | OK = 1; 95 | INVALID_TRANSACTION = 2; 96 | INTERNAL_ERROR = 3; 97 | } 98 | 99 | Status status = 1; 100 | 101 | // A message to include on responses in the cases where 102 | // status is either INVALID_TRANSACTION or INTERNAL_ERROR 103 | string message = 2; 104 | 105 | // Information that may be included with the response. 106 | // This information is an opaque, application-specific encoded block of 107 | // data that will be propagated back to the transaction submitter. 108 | bytes extended_data = 3; 109 | } 110 | -------------------------------------------------------------------------------- /protos/setting.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 | option java_multiple_files = true; 18 | option java_package = "sawtooth.sdk.protobuf"; 19 | option go_package = "protobuf/setting_pb2"; 20 | 21 | 22 | // Setting Container for on-chain configuration key/value pairs 23 | message Setting { 24 | // Contains a setting entry (or entries, in the case of collisions). 25 | message Entry { 26 | string key = 1; 27 | string value = 2; 28 | } 29 | 30 | // List of setting entries - more than one implies a state key collision 31 | repeated Entry entries = 1; 32 | } 33 | -------------------------------------------------------------------------------- /protos/state_context.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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 | option java_multiple_files = true; 18 | option java_package = "sawtooth.sdk.protobuf"; 19 | option go_package = "protobuf/state_context_pb2"; 20 | 21 | import "events.proto"; 22 | 23 | // An entry in the State 24 | message TpStateEntry { 25 | string address = 1; 26 | bytes data = 2; 27 | } 28 | 29 | // A request from a handler/tp for the values at a series of addresses 30 | message TpStateGetRequest { 31 | // The context id that references a context in the contextmanager 32 | string context_id = 1; 33 | repeated string addresses = 2; 34 | } 35 | 36 | // A response from the contextmanager/validator with a series of State entries 37 | message TpStateGetResponse { 38 | enum Status { 39 | STATUS_UNSET = 0; 40 | OK = 1; 41 | AUTHORIZATION_ERROR = 2; 42 | } 43 | 44 | repeated TpStateEntry entries = 1; 45 | Status status = 2; 46 | } 47 | 48 | // A request from the handler/tp to put entries in the state of a context 49 | message TpStateSetRequest { 50 | string context_id = 1; 51 | repeated TpStateEntry entries = 2; 52 | } 53 | 54 | // A response from the contextmanager/validator with the addresses that were set 55 | message TpStateSetResponse { 56 | enum Status { 57 | STATUS_UNSET = 0; 58 | OK = 1; 59 | AUTHORIZATION_ERROR = 2; 60 | } 61 | 62 | repeated string addresses = 1; 63 | Status status = 2; 64 | } 65 | 66 | // A request from the handler/tp to delete state entries at an collection of addresses 67 | message TpStateDeleteRequest { 68 | string context_id = 1; 69 | repeated string addresses = 2; 70 | } 71 | 72 | // A response form the contextmanager/validator with the addresses that were deleted 73 | message TpStateDeleteResponse { 74 | enum Status { 75 | STATUS_UNSET = 0; 76 | OK = 1; 77 | AUTHORIZATION_ERROR = 2; 78 | } 79 | 80 | repeated string addresses = 1; 81 | Status status = 2; 82 | } 83 | 84 | // The request from the transaction processor to the validator append data 85 | // to a transaction receipt 86 | message TpReceiptAddDataRequest { 87 | // The context id that references a context in the context manager 88 | string context_id = 1; 89 | bytes data = 3; 90 | } 91 | 92 | // The response from the validator to the transaction processor to verify that 93 | // data has been appended to a transaction receipt 94 | message TpReceiptAddDataResponse { 95 | enum Status { 96 | STATUS_UNSET = 0; 97 | OK = 1; 98 | ERROR = 2; 99 | } 100 | 101 | Status status = 2; 102 | } 103 | 104 | message TpEventAddRequest { 105 | string context_id = 1; 106 | Event event = 2; 107 | } 108 | 109 | message TpEventAddResponse { 110 | enum Status { 111 | STATUS_UNSET = 0; 112 | OK = 1; 113 | ERROR = 2; 114 | } 115 | Status status = 2; 116 | } 117 | -------------------------------------------------------------------------------- /protos/transaction.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 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.sdk.protobuf"; 20 | option go_package = "protobuf/transaction_pb2"; 21 | 22 | message TransactionHeader { 23 | // Public key for the client who added this transaction to a batch 24 | string batcher_public_key = 1; 25 | 26 | // A list of transaction signatures that describe the transactions that 27 | // must be processed before this transaction can be valid 28 | repeated string dependencies = 2; 29 | 30 | // The family name correlates to the transaction processor's family name 31 | // that this transaction can be processed on, for example 'intkey' 32 | string family_name = 3; 33 | 34 | // The family version correlates to the transaction processor's family 35 | // version that this transaction can be processed on, for example "1.0" 36 | string family_version = 4; 37 | 38 | // A list of addresses that are given to the context manager and control 39 | // what addresses the transaction processor is allowed to read from. 40 | repeated string inputs = 5; 41 | 42 | // A random string that provides uniqueness for transactions with 43 | // otherwise identical fields. 44 | string nonce = 6; 45 | 46 | // A list of addresses that are given to the context manager and control 47 | // what addresses the transaction processor is allowed to write to. 48 | repeated string outputs = 7; 49 | 50 | //The sha512 hash of the encoded payload 51 | string payload_sha512 = 9; 52 | 53 | // Public key for the client that signed the TransactionHeader 54 | string signer_public_key = 10; 55 | } 56 | 57 | message Transaction { 58 | // The serialized version of the TransactionHeader 59 | bytes header = 1; 60 | 61 | // The signature derived from signing the header 62 | string header_signature = 2; 63 | 64 | // The payload is the encoded family specific information of the 65 | // transaction. Example cbor({'Verb': verb, 'Name': name,'Value': value}) 66 | bytes payload = 3; 67 | } 68 | 69 | // A simple list of transactions that needs to be serialized before 70 | // it can be transmitted to a batcher. 71 | message TransactionList { 72 | repeated Transaction transactions = 1; 73 | } 74 | -------------------------------------------------------------------------------- /protos/transaction_receipt.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.sdk.protobuf"; 20 | option go_package = "protobuf/txn_receipt_pb2"; 21 | 22 | import "events.proto"; 23 | 24 | 25 | message TransactionReceipt { 26 | // State changes made by this transaction 27 | // StateChange is defined in protos/transaction_receipt.proto 28 | repeated StateChange state_changes = 1; 29 | // Events fired by this transaction 30 | repeated Event events = 2; 31 | // Transaction family defined data 32 | repeated bytes data = 3; 33 | 34 | string transaction_id = 4; 35 | } 36 | 37 | // StateChange objects have the type of SET, which is either an insert or 38 | // update, or DELETE. Items marked as a DELETE will have no byte value. 39 | message StateChange { 40 | enum Type { 41 | TYPE_UNSET = 0; 42 | SET = 1; 43 | DELETE = 2; 44 | } 45 | string address = 1; 46 | bytes value = 2; 47 | Type type = 3; 48 | } 49 | 50 | // A collection of state changes. 51 | message StateChangeList { 52 | repeated StateChange state_changes = 1; 53 | } 54 | -------------------------------------------------------------------------------- /signing/core.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 signing 19 | 20 | // -- Keys -- 21 | 22 | // A private key instance. The underlying content is dependent on 23 | // implementation. 24 | type PrivateKey interface { 25 | // Returns the algorithm name used for this private key. 26 | GetAlgorithmName() string 27 | 28 | // Returns the private key encoded as a hex string. 29 | AsHex() string 30 | 31 | // Returns the private key bytes. 32 | AsBytes() []byte 33 | } 34 | 35 | // A public key instance. The underlying content is dependent on 36 | // implementation. 37 | type PublicKey interface { 38 | // Returns the algorithm name used for this public key. 39 | GetAlgorithmName() string 40 | 41 | // Returns the public key encoded as a hex string. 42 | AsHex() string 43 | 44 | // Returns the public key bytes. 45 | AsBytes() []byte 46 | } 47 | 48 | // -- Context -- 49 | 50 | // A context for a cryptographic signing algorithm. 51 | type Context interface { 52 | // Returns the algorithm name used for this context. 53 | GetAlgorithmName() string 54 | 55 | // Generates a new random private key. 56 | NewRandomPrivateKey() PrivateKey 57 | 58 | // Produces a public key for the given private key. 59 | GetPublicKey(private_key PrivateKey) PublicKey 60 | 61 | // Sign uses the given private key to calculate a signature for 62 | // the given data. 63 | Sign(message []byte, private_key PrivateKey) []byte 64 | 65 | // Verify uses the given public key to verify that the given 66 | // signature was created from the given data using the associated 67 | // private key. 68 | Verify(signature []byte, message []byte, public_key PublicKey) bool 69 | } 70 | 71 | // Returns a Context instance by name. 72 | func CreateContext(algorithmName string) Context { 73 | if algorithmName == "secp256k1" { 74 | return NewSecp256k1Context() 75 | } 76 | 77 | panic("No such algorithm") 78 | } 79 | 80 | // -- Signer -- 81 | 82 | // A convenient wrapper of Context and PrivateKey. 83 | type Signer struct { 84 | context Context 85 | private_key PrivateKey 86 | } 87 | 88 | // Signs the given message. 89 | func (self *Signer) Sign(message []byte) []byte { 90 | return self.context.Sign(message, self.private_key) 91 | } 92 | 93 | // Returns the public key for this Signer instance. 94 | func (self *Signer) GetPublicKey() PublicKey { 95 | return self.context.GetPublicKey(self.private_key) 96 | } 97 | 98 | // -- CryptoFactory -- 99 | 100 | // A factory for generating Signers. 101 | type CryptoFactory struct { 102 | context Context 103 | } 104 | 105 | // Creates a factory for generating Signers. 106 | func NewCryptoFactory(context Context) *CryptoFactory { 107 | return &CryptoFactory{context: context} 108 | } 109 | 110 | // Returns the context that backs this Factory instance. 111 | func (self *CryptoFactory) GetContext() Context { 112 | return self.context 113 | } 114 | 115 | // Creates a new Signer for the given private key. 116 | func (self *CryptoFactory) NewSigner(private_key PrivateKey) *Signer { 117 | return &Signer{self.context, private_key} 118 | } 119 | -------------------------------------------------------------------------------- /signing/pem_loader.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 signing 19 | 20 | // #cgo LDFLAGS: -lcrypto 21 | // #cgo pkg-config: openssl 22 | // #include "../c/c11_support.h" 23 | // #include "../c/c11_support.c" 24 | // #include "../c/loader.c" 25 | import "C" 26 | 27 | import "fmt" 28 | 29 | func loadPemKey(pemstr string, pemstrLen int, password string) (priv_key string, pub_key string, err error) { 30 | cPemstr := C.CString(pemstr) 31 | cPemstrLen := C.size_t(pemstrLen) 32 | cPassword := C.CString(password) 33 | cOutPrivKey := C.CString("-----------------------------------------------------------------") 34 | cOutPubKey := C.CString("-----------------------------------------------------------------------------------------------------------------------------------") 35 | errnum := C.load_pem_key(cPemstr, cPemstrLen, cPassword, cOutPrivKey, cOutPubKey) 36 | if errnum < 0 { 37 | var errstr string 38 | switch errnum { 39 | case -1: 40 | errstr = "Failed to decrypt or decode private key" 41 | case -2: 42 | errstr = "Failed to create new big number context" 43 | case -3: 44 | errstr = "Failed to load group" 45 | case -4: 46 | errstr = "Failed to load private key" 47 | case -5: 48 | errstr = "Failed to load public key point" 49 | case -6: 50 | errstr = "Failed to construct public key from point" 51 | } 52 | return "", "", fmt.Errorf(errstr) 53 | } 54 | return C.GoString(cOutPrivKey), C.GoString(cOutPubKey), nil 55 | } 56 | -------------------------------------------------------------------------------- /tests/integration-tests.dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | FROM ubuntu:bionic 16 | 17 | RUN apt-get update \ 18 | && apt-get install gnupg -y 19 | 20 | RUN echo "deb [arch=amd64] http://repo.sawtooth.me/ubuntu/ci bionic universe" >> /etc/apt/sources.list \ 21 | && (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8AA7AF1F1091A5FD \ 22 | || apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 8AA7AF1F1091A5FD) \ 23 | && apt-get update 24 | 25 | RUN apt-get install -y -q \ 26 | apt-transport-https \ 27 | curl \ 28 | python3-aiohttp \ 29 | python3-cbor \ 30 | python3-colorlog \ 31 | python3-cov-core \ 32 | python3-cryptography-vectors \ 33 | python3-cryptography \ 34 | python3-dev \ 35 | python3-lmdb \ 36 | python3-nose2 \ 37 | python3-pip \ 38 | python3-protobuf \ 39 | python3-pyformance \ 40 | python3-requests \ 41 | python3-secp256k1 \ 42 | python3-toml \ 43 | python3-yaml \ 44 | python3-zmq \ 45 | software-properties-common 46 | 47 | RUN pip3 install \ 48 | coverage --upgrade 49 | 50 | RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \ 51 | && add-apt-repository \ 52 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 53 | $(lsb_release -cs) \ 54 | stable" 55 | 56 | RUN apt-get update && apt-get install -y -q \ 57 | docker-ce 58 | 59 | ENV PATH=$PATH:/project/sawtooth-core/bin 60 | 61 | WORKDIR /project/sawtooth-core 62 | -------------------------------------------------------------------------------- /tests/state_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 | "fmt" 22 | "github.com/golang/mock/gomock" 23 | "github.com/golang/protobuf/proto" 24 | "github.com/hyperledger/sawtooth-sdk-go/messaging" 25 | "github.com/hyperledger/sawtooth-sdk-go/mocks/mock_messaging" 26 | "github.com/hyperledger/sawtooth-sdk-go/processor" 27 | "github.com/hyperledger/sawtooth-sdk-go/protobuf/events_pb2" 28 | "github.com/hyperledger/sawtooth-sdk-go/protobuf/state_context_pb2" 29 | "github.com/hyperledger/sawtooth-sdk-go/protobuf/validator_pb2" 30 | "testing" 31 | ) 32 | 33 | func TestState(t *testing.T) { 34 | mockCtrl := gomock.NewController(t) 35 | defer mockCtrl.Finish() 36 | 37 | var connection messaging.Connection 38 | mock_connection := mock_messaging.NewMockConnection(mockCtrl) 39 | connection = mock_connection 40 | context := processor.NewContext(connection, "abc") 41 | 42 | request := &state_context_pb2.TpStateGetRequest{ 43 | ContextId: "abc", 44 | Addresses: []string{"abc"}, 45 | } 46 | bytes, _ := proto.Marshal(request) 47 | 48 | mock_connection.EXPECT().SendNewMsg(validator_pb2.Message_TP_STATE_GET_REQUEST, bytes) 49 | mock_connection.EXPECT().RecvMsgWithId("") 50 | 51 | context.GetState([]string{"abc"}) 52 | } 53 | 54 | func TestAddEvent(t *testing.T) { 55 | mockCtrl := gomock.NewController(t) 56 | defer mockCtrl.Finish() 57 | 58 | var connection messaging.Connection 59 | mock_connection := mock_messaging.NewMockConnection(mockCtrl) 60 | connection = mock_connection 61 | context := processor.NewContext(connection, "asdf") 62 | 63 | event_attributes := make([]*events_pb2.Event_Attribute, 0) 64 | event_attributes = append( 65 | event_attributes, 66 | &events_pb2.Event_Attribute{ 67 | Key: "key", 68 | Value: "value", 69 | }, 70 | ) 71 | 72 | event := &events_pb2.Event{ 73 | EventType: "test", 74 | Attributes: event_attributes, 75 | Data: []byte("data"), 76 | } 77 | 78 | request := &state_context_pb2.TpEventAddRequest{ 79 | ContextId: "asdf", 80 | Event: event, 81 | } 82 | request_bytes, _ := proto.Marshal(request) 83 | 84 | response_bytes, err := proto.Marshal(&state_context_pb2.TpEventAddResponse{ 85 | Status: state_context_pb2.TpEventAddResponse_OK, 86 | }) 87 | 88 | mock_connection.EXPECT().SendNewMsg(validator_pb2.Message_TP_EVENT_ADD_REQUEST, request_bytes) 89 | mock_connection.EXPECT().RecvMsgWithId(""). 90 | Return( 91 | "", 92 | &validator_pb2.Message{ 93 | MessageType: validator_pb2.Message_TP_EVENT_ADD_RESPONSE, 94 | CorrelationId: "", 95 | Content: response_bytes, 96 | }, 97 | err) 98 | 99 | attributes := []processor.Attribute{{"key", "value"}} 100 | add_event_err := context.AddEvent("test", attributes, []byte("data")) 101 | if add_event_err != nil { 102 | t.Error(fmt.Errorf("ERROR: %s", add_event_err)) 103 | } 104 | } 105 | 106 | func TestReceiptData(t *testing.T) { 107 | mockCtrl := gomock.NewController(t) 108 | defer mockCtrl.Finish() 109 | 110 | var connection messaging.Connection 111 | mock_connection := mock_messaging.NewMockConnection(mockCtrl) 112 | connection = mock_connection 113 | context := processor.NewContext(connection, "qwerty") 114 | 115 | request := &state_context_pb2.TpReceiptAddDataRequest{ 116 | ContextId: "qwerty", 117 | Data: []byte("receiptdata"), 118 | } 119 | bytes, _ := proto.Marshal(request) 120 | 121 | mock_connection.EXPECT().SendNewMsg(validator_pb2.Message_TP_RECEIPT_ADD_DATA_REQUEST, bytes) 122 | mock_connection.EXPECT().RecvMsgWithId("") 123 | 124 | context.AddReceiptData([]byte("receiptdata")) 125 | } 126 | -------------------------------------------------------------------------------- /tests/test_systemd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 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 | # A simple test to verify that the each systemd service is able to startup 18 | # without immediately crashing given the default arguments 19 | 20 | services=" 21 | smallbank-tp-go 22 | xo-tp-go 23 | intkey-tp-go 24 | noop-tp-go 25 | " 26 | 27 | if [ -z $ISOLATION_ID ] 28 | then 29 | ISOLATION_ID=latest 30 | fi 31 | 32 | for serv in $services 33 | do 34 | # 1. Create a docker container running systemd 35 | image=sawtooth-$serv:$ISOLATION_ID 36 | container=${ISOLATION_ID}_systemd_test_$serv 37 | service=sawtooth-$serv 38 | echo "Starting container '$container' from '$image'..." 39 | docker run -d --name $container --privileged --rm $image systemd 40 | sleep 1 # Give systemd a chance to start 41 | 42 | if [ $serv = "validator" ] 43 | then 44 | echo "Running keygen in $container..." 45 | docker exec $container sawadm keygen 46 | fi 47 | 48 | # 2. Start the systemd service in the container 49 | echo "Starting $service in $container..." 50 | docker exec $container systemctl start $service 51 | sleep 1 # Give the service a chance to fail 52 | 53 | # 3. Check if the service started successfully 54 | docker exec $container systemctl status $service 55 | exitcode=$? 56 | echo "Exit code was $exitcode" 57 | 58 | # 4. Cleanup the container 59 | docker kill $container 60 | 61 | if [ $exitcode -ne 0 ] 62 | then 63 | exit $exitcode 64 | fi 65 | done 66 | -------------------------------------------------------------------------------- /tests/test_systemd_services.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 | test-systemd-services: 20 | build: 21 | context: ../ 22 | dockerfile: tests/integration-tests.dockerfile 23 | image: integration-tests:$ISOLATION_ID 24 | volumes: 25 | - $CORE:/project/sawtooth-sdk-go 26 | - /var/run/docker.sock:/var/run/docker.sock 27 | command: /project/sawtooth-sdk-go/tests/test_systemd.sh 28 | environment: 29 | ISOLATION_ID: ${ISOLATION_ID} 30 | --------------------------------------------------------------------------------