Skip to content

Commit

Permalink
generic client CLI (integritee-network#94)
Browse files Browse the repository at this point in the history
+moved from hardcoded client example to generic CLI
+added M5 demo bash script similar to old M5 demo
+stf functions CLI are defined in stf crate for easy customization by third parties
  • Loading branch information
brenzi committed Feb 26, 2020
1 parent 0786b70 commit 5220a75
Show file tree
Hide file tree
Showing 31 changed files with 1,308 additions and 709 deletions.
15 changes: 13 additions & 2 deletions .gitignore
Expand Up @@ -7,7 +7,7 @@

# binaries
bin/*.so
bin/substratee_*
bin/substratee-*
bin/*.wasm

# sealed data
Expand All @@ -24,6 +24,8 @@ bin/ecc_pubkey.txt
.idea/
*.iml

*.log

# generated enclave files
worker/Enclave_u.*
worker/libEnclave_u.*
Expand All @@ -41,8 +43,17 @@ bin/spid_production.txt
bin/key.txt
bin/key_production.txt
bin/attestation_report.json
bin/shards
bin/*.der
bin/enclave-shielding-pubkey.json

# in order to have 2 workers run and exchange keys
bin2/substratee_worker
bin2/substratee-worker
bin2/*.bin
bin2/*.txt
bin2/shards
bin2/enclave-shielding-pubkey.json

# client
client/my_keystore
client/my_trusted_keystore
119 changes: 78 additions & 41 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -5,8 +5,8 @@ members = [
"substratee-node-calls",
"client",
"stf",
"substrate-sgx/externalities",
"substrate-sgx/sr-io",
"substrate-sgx/runtime"
# "substrate-sgx/externalities",
# "substrate-sgx/sr-io",
# "substrate-sgx/runtime"
# "enclave",
]
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -122,7 +122,7 @@ Client_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(Worker_Include_Pa

Client_Rust_Path := target/$(OUTPUT_PATH)
Client_Path := bin
Client_Binary := substratee_client
Client_Binary := substratee-client
Client_Name := $(Client_Path)/$(Client_Binary)

######## Enclave settings ########
Expand Down Expand Up @@ -181,8 +181,8 @@ $(Worker_Name): $(Worker_Enclave_u_Object) $(Worker_SRC_Files)
@echo "Building the substraTEE-worker"
@cd worker && SGX_SDK=$(SGX_SDK) cargo build $(Worker_Rust_Flags)
@echo "Cargo => $@"
cp $(Worker_Rust_Path)/substratee_worker ./bin
cp $(Worker_Rust_Path)/substratee_worker ./bin2
cp $(Worker_Rust_Path)/substratee-worker ./bin
cp $(Worker_Rust_Path)/substratee-worker ./bin2

######## SubstraTEE-client objects ########
$(Client_Name): $(Client_SRC_Files)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -49,13 +49,13 @@ cd substraTEE-worker
git checkout tags/M5
make
cd bin
RUST_LOG=info ./substratee_worker -p 9979 worker
RUST_LOG=info ./substratee-worker -p 9979 worker
```

in terminal 3, run the client
```
cd substraTEE-worker/bin
./substratee_client --node-ws-port 9979
./substratee-client --node-ws-port 9979
```

Then you should see this in terminal 3:
Expand Down Expand Up @@ -136,5 +136,5 @@ substraTEE-worker/bin$ touch sealed_stf_state.bin
### execute tests
Run these with
```
substraTEE-worker/bin$ ./substratee_worker test_enclave --all
substraTEE-worker/bin$ ./substratee-worker test_enclave --all
```
98 changes: 54 additions & 44 deletions client/Cargo.toml
@@ -1,73 +1,83 @@
[package]
name = "substratee_client"
name = "substratee-client"
version = "4.0.0"
authors = ["Supercomputing Systems AG <info@scs.ch>"]
edition = "2018"

[dependencies]
substrate-api-client = { tag = "api-M1.5", git = "https://github.com/scs/substrate-api-client.git"}
log = "0.4"
env_logger = "0.7.1"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
env_logger = "0.7"
hex = "0.4"
json = "0.12.0"
substrate-bip39 = "0.3.1"
tiny-bip39 = "0.6.2"
serde_json = "1.0"
clap = "2.33"
clap-nested = "0.3.1"
primitive-types = { version = "0.6.1", default-features = false, features = ["codec"] }
base58 = "0.1"
chrono = "*"
base58 = "0.1"

clap = { version = "2.33", features = [ "yaml" ] }
blake2-rfc = { version = "0.2.18", default-features = false}
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
primitive-types = { version = "0.6", default-features = false, features = ["codec"] }

sgx_types = { rev = "v1.1.0",git = "https://github.com/apache/teaclave-sgx-sdk.git" }
sgx_crypto_helper = { rev = "v1.1.0",git = "https://github.com/apache/teaclave-sgx-sdk.git", default-features = false }
[dependencies.serde]
features = ["derive"]
optional = true
version = "1.0"

[dependencies.my_node_runtime]
git = "https://github.com/scs/substraTEE-node"
rev = "7328b37166fdffcc74cf11763084d67029945df9"
package = "substratee-node-runtime"
[dependencies.codec]
default-features = false
package = "parity-scale-codec"
features = ["derive"]
version = "1.0.0"

[dependencies.substrate-api-client]
git = "https://github.com/scs/substrate-api-client"
tag = "api-M1.5"
[dependencies.primitives]
git = 'https://github.com/paritytech/substrate'
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "substrate-primitives"

[dependencies.substratee-node-calls]
path = "../substratee-node-calls"
[dependencies.sr-primitives]
git = "https://github.com/paritytech/substrate"
package = "sr-primitives"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"

[dependencies.substratee_worker_api]
path = "../worker/worker-api"
[dependencies.keystore]
git = 'https://github.com/paritytech/substrate'
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "substrate-keystore"

[dependencies.balances]
git = 'https://github.com/paritytech/substrate'
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "pallet-balances"
default-features=false

[dependencies.system]
git = "https://github.com/paritytech/substrate"
git = 'https://github.com/paritytech/substrate'
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "palette-system"
default-features=false

[dependencies.primitives]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "substrate-primitives"
features = ["full_crypto"]
[dependencies.substratee-node-runtime]
git = "https://github.com/scs/substraTEE-node"
rev = "e09d5c51287d240df904b5dc98c4a9f59ac7c002"
package = "substratee-node-runtime"

[dependencies.node-primitives]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
[dependencies.substratee-stf]
path = "../stf"

[dependencies.substratee-worker-api]
path = "../worker/worker-api"

[dependencies.keyring]
git = "https://github.com/paritytech/substrate"
git = 'https://github.com/paritytech/substrate'
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "substrate-keyring"

[dependencies.runtime_primitives]
[dependencies.app-crypto]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "sr-primitives"
#default-features = false
package = "substrate-application-crypto"

[dependencies.indices]
git = "https://github.com/paritytech/substrate"
rev = "3bf9540e72df5ecb3955845764dfee7dcdbb26b5"
package = "pallet-indices"

[dependencies.substratee-stf]
path = "../stf"
default-features = false
#[patch.crates-io]
#ed25519-dalek = { git = "https://github.com/scs/ed25519-dalek.git", branch = "no_std_sgx"}
20 changes: 20 additions & 0 deletions client/README.md
@@ -0,0 +1,20 @@
# SubstraTEE CLI client
Interact with the SubstraTEE chain and workers from the command line

Includes
* keystore (incompatible with polkadot js app json)
* basic balance transfer
* SubstraTEE-specific calls

## examples
```
> substratee-client new-account
> substratee-client 127.0.0.1 transfer 5GpuFm6t1AU9xpTAnQnHXakTGA9rSHz8xNkEvx7RVQz2BVpd 5FkGDttiYa9ZoDAuNxzwEdLzkgt6ngWykSBhobGvoFUcUo8B 12345
> substratee-client 127.0.0.1:9979 list-workers
number of workers registered: 1
Enclave 1
AccountId: 5DvVAZAWnFS6ufCteSbuh46miVUCQH5oZ231SXHQGswCdGx9
MRENCLAVE: HvKRosdfbbLayao3rAq4xmN2fnxBVX79DfDdeJ9YcTo5
RA timestamp: 2020-02-22 06:32:37 UTC
URL: 127.0.0.1:2000
```
43 changes: 43 additions & 0 deletions client/demo_private_tx.sh
@@ -0,0 +1,43 @@
#!/bin/bash

# setup:
# run all on localhost:
# run substratee-node --dev --ws-port 9979 -lruntime=debug
# run substratee-worker -p 9979 run
#
# then run this script

CLIENT="../target/release/substratee-client -p 9979 "

echo "query on-chain enclave registry:"
$CLIENT list-workers
echo ""

# does this work when multiple workers are in the registry?
read MRENCLAVE <<< $($CLIENT list-workers | awk '/ MRENCLAVE:[[:space:]]/ { print $2 }')

# only for initial setup (actually should be done in genesis)
# pre-fund //AliceIncognito, our ROOT key
echo "issue funds on first (sender) account:"
$CLIENT trusted set-balance //AliceIncognito 123456789 --mrenclave $MRENCLAVE
echo -n "get balance: "
$CLIENT trusted balance //AliceIncognito --mrenclave $MRENCLAVE

## create a new on-chain account and fund it form faucet
#account1=$($CLIENT new-account)
#echo "*** created new on-chain account: $account1"
#echo "*** funding that account from faucet"
#$CLIENT faucet $account1

# create incognito account for default shard (= MRENCLAVE)
account1p=$($CLIENT trusted new-account --mrenclave $MRENCLAVE)
echo "created new incognito account: $account1p"

#send 10M funds from AliceIncognito to new account
$CLIENT trusted transfer //AliceIncognito $account1p 23456789 --mrenclave $MRENCLAVE

echo -n "receiver balance: "
$CLIENT trusted balance $account1p --mrenclave $MRENCLAVE

echo -n "sender balance: "
$CLIENT trusted balance //AliceIncognito --mrenclave $MRENCLAVE
37 changes: 0 additions & 37 deletions client/src/cli.yml

This file was deleted.

0 comments on commit 5220a75

Please sign in to comment.