This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
forked from drr00t/parity-poa-playground
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathacl.sh
69 lines (40 loc) · 2.33 KB
/
acl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
alice=$1
bob=$2
PASSWORD=$3
DOC=$(echo mySecretDocument | sha256sum| awk '{ print $1 }')
green=`tput setaf 2`
reset=`tput sgr0`
cp contracts/example.sol contracts/contract.sol
sed -i '' -e s,alicer,$alice,g -e s,bobr,$bob,g contracts/contract.sol
# Compile acl contract
docker run -v $PWD/contracts:/solidity ethereum/solc:0.4.24 --bin -o . contract.sol --overwrite
docker-compose up -d alice bob charlie ss1 ss2 ss3
sleep 10
printf "Generating Secret Store key\n"
RES=$(curl -s --data-binary '{"jsonrpc": "2.0", "method": "secretstore_signRawHash", "params": ["'$alice'", "'$PASSWORD'", "'0x$DOC'"], "id":1 }' -H 'content-type: application/json' localhost:8545 |jq .result| tr -d '"'|cut -d "x" -f 2)
sleep 2
SSSKEY=$(curl -s -X POST http://localhost:8010/shadow/$DOC/$RES/1)
echo "$SSSKEY">SSSkey.txt
sleep 3
bytecode="0x$(cat contracts/SSPermissions.bin)"
printf "Compose contract create\n"
COMPOSE=$(curl -s --data '{"method":"parity_composeTransaction","params":[{"from":"'$alice'", "data":"'$bytecode'"}],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545| jq .result)
GAS=$(echo $COMPOSE | jq .gas)
NONCE=$(echo $COMPOSE | jq .nonce)
sleep 2
printf "Sign contract\n"
SIGNED=$(curl -s --data '{"method":"personal_signTransaction","params":[{"condition":null,"data":"'$bytecode'","from":"'$alice'","gas":'$GAS',"gasPrice":"0x0","nonce":'$NONCE',"to":null,"value":"0x0"},"'$PASSWORD'"],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545 | jq .result)
CONTRACTRAW=$(echo $SIGNED | jq .raw)
sleep 2
printf "Sending contract: \n"
RESULT=$(curl -s --data '{"method":"eth_sendRawTransaction","params":['$CONTRACTRAW'],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545|jq .result)
echo -e "${green}$RESULT${reset}"
sleep 2
ADDRESS=$(curl -s --data '{"method":"eth_getTransactionReceipt","params":['$RESULT'],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST localhost:8545|jq '.result .contractAddress')
# cut x again
ADDRESSx=$(echo $ADDRESS|cut -d "x" -f 2)
# insert contract address in ss nodes
docker kill $(docker ps -q)
sed -i '' -e 's,acl_contract = "none",acl_contract = "'$ADDRESSx',g' parity/config/secret/ss1.toml parity/config/secret/ss2.toml parity/config/secret/ss3.toml
echo -e "${green}ACL deployed${reset}"