forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rosetta API implementation (cosmos#7695)
Ref: cosmos#7492 Co-authored-by: Jonathan Gimeno <[email protected]> Co-authored-by: Alessio Treglia <[email protected]> Co-authored-by: Frojdi Dymylja <[email protected]> Co-authored-by: Robert Zaremba <[email protected]> Co-authored-by: Federico Kunze <[email protected]>
- Loading branch information
1 parent
d226254
commit 57f5e96
Showing
46 changed files
with
2,886 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# rosetta | ||
|
||
This directory contains the files required to run the rosetta CI. It builds `simapp` based on the current codebase. | ||
|
||
## docker-compose.yaml | ||
|
||
Builds: | ||
- cosmos-sdk simapp node, with prefixed data directory, keys etc. This is required to test historical balances. | ||
- faucet is required so we can test construction API, it was literally impossible to put there a deterministic address to request funds for | ||
- rosetta is the rosetta node used by rosetta-cli to interact with the cosmos-sdk app | ||
- test_rosetta runs the rosetta-cli test against construction API and data API | ||
|
||
## configuration | ||
|
||
Contains the required files to set up rosetta cli and make it work against its workflows | ||
|
||
## node | ||
|
||
Contains the files for a deterministic network, with fixed keys and some actions on there, to test parsing of msgs and historical balances. | ||
|
||
## Notes | ||
|
||
- Keyring password is 12345678 | ||
- data.sh creates node data, it's required in case consensus breaking changes are made to quickly recreate replicable node data for rosetta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"account_identifier": { | ||
"address":"cosmos1hdmjfmqmf8ck4pv4evu0s3up0ucm0yjjqfl87e" | ||
}, | ||
"currency":{ | ||
"symbol":"stake", | ||
"decimals":0 | ||
}, | ||
"value": "999900000000" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
wait_simd() { | ||
timeout 30 sh -c 'until nc -z $0 $1; do sleep 1; done' localhost 9090 | ||
} | ||
# this script is used to recreate the data dir | ||
echo clearing /root/.simapp | ||
rm -rf /root/.simapp | ||
echo initting new chain | ||
# init config files | ||
simd init simd --chain-id testing | ||
|
||
# create accounts | ||
simd keys add fd --keyring-backend=test | ||
|
||
addr=$(simd keys show fd -a --keyring-backend=test) | ||
|
||
# give the accounts some money | ||
simd add-genesis-account "$addr" 1000000000000stake --keyring-backend=test | ||
|
||
# save configs for the daemon | ||
simd gentx fd --chain-id testing --keyring-backend=test | ||
|
||
# input genTx to the genesis file | ||
simd collect-gentxs | ||
# verify genesis file is fine | ||
simd validate-genesis | ||
echo changing network settings | ||
sed -i 's/127.0.0.1/0.0.0.0/g' /root/.simapp/config/config.toml | ||
|
||
# start simd | ||
echo starting simd... | ||
simd start --pruning=nothing & | ||
pid=$! | ||
echo simd started with PID $pid | ||
|
||
echo awaiting for simd to be ready | ||
wait_simd | ||
echo simd is ready | ||
sleep 10 | ||
|
||
|
||
# send transaction to deterministic address | ||
echo sending transaction with addr $addr | ||
simd tx bank send "$addr" cosmos1wjmt63j4fv9nqda92nsrp2jp2vsukcke4va3pt 100stake --yes --keyring-backend=test --broadcast-mode=block --chain-id=testing | ||
|
||
sleep 10 | ||
|
||
echo stopping simd... | ||
kill -9 $pid | ||
|
||
echo zipping data dir and saving to /tmp/data.tar.gz | ||
|
||
tar -czvf /tmp/data.tar.gz /root/.simapp | ||
|
||
echo new address for bootstrap.json "$addr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from http.server import HTTPServer, BaseHTTPRequestHandler | ||
import subprocess | ||
|
||
import os | ||
|
||
|
||
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): | ||
|
||
def do_POST(self): | ||
try: | ||
content_len = int(self.headers.get('Content-Length')) | ||
addr = self.rfile.read(content_len).decode("utf-8") | ||
print("sending funds to " + addr) | ||
subprocess.call(['sh', './send_funds.sh', addr]) | ||
self.send_response(200) | ||
self.end_headers() | ||
except Exception as e: | ||
print("failed " + str(e)) | ||
os._exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
print("starting faucet server...") | ||
httpd = HTTPServer(('0.0.0.0', 8000), SimpleHTTPRequestHandler) | ||
httpd.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"network": { | ||
"blockchain": "app", | ||
"network": "network" | ||
}, | ||
"online_url": "http://rosetta:8080", | ||
"data_directory": "", | ||
"http_timeout": 300, | ||
"max_retries": 5, | ||
"retry_elapsed_time": 0, | ||
"max_online_connections": 0, | ||
"max_sync_concurrency": 0, | ||
"tip_delay": 60, | ||
"log_configuration": true, | ||
"construction": { | ||
"offline_url": "http://rosetta:8080", | ||
"max_offline_connections": 0, | ||
"stale_depth": 0, | ||
"broadcast_limit": 0, | ||
"ignore_broadcast_failures": false, | ||
"clear_broadcasts": false, | ||
"broadcast_behind_tip": false, | ||
"block_broadcast_limit": 0, | ||
"rebroadcast_all": false, | ||
"constructor_dsl_file": "transfer.ros", | ||
"end_conditions": { | ||
"create_account": 1, | ||
"transfer": 3 | ||
} | ||
}, | ||
"data": { | ||
"active_reconciliation_concurrency": 0, | ||
"inactive_reconciliation_concurrency": 0, | ||
"inactive_reconciliation_frequency": 0, | ||
"log_blocks": false, | ||
"log_transactions": false, | ||
"log_balance_changes": false, | ||
"log_reconciliations": false, | ||
"ignore_reconciliation_error": false, | ||
"exempt_accounts": "", | ||
"bootstrap_balances": "bootstrap.json", | ||
"interesting_accounts": "", | ||
"reconciliation_disabled": false, | ||
"inactive_discrepency_search_disabled": false, | ||
"balance_tracking_disabled": false, | ||
"coin_tracking_disabled": false, | ||
"end_conditions": { | ||
"tip": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
addr="abcd" | ||
|
||
send_tx() { | ||
echo '12345678' | simd tx bank send $addr "$1" "$2" | ||
} | ||
|
||
detect_account() { | ||
line=$1 | ||
} | ||
|
||
wait_for_rosetta() { | ||
timeout 30 sh -c 'until nc -z $0 $1; do sleep 1; done' rosetta 8080 | ||
} | ||
|
||
echo "waiting for rosetta instance to be up" | ||
wait_for_rosetta | ||
|
||
echo "checking data API" | ||
rosetta-cli check:data --configuration-file ./config/rosetta.json | ||
|
||
echo "checking construction API" | ||
rosetta-cli check:construction --configuration-file ./config/rosetta.json | ||
|
||
echo "checking staking API" | ||
rosetta-cli check:construction --configuration-file ./config/staking.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
addr=$(simd keys show fd -a --keyring-backend=test) | ||
echo "12345678" | simd tx bank send "$addr" "$1" 100stake --chain-id="testing" --node tcp://cosmos:26657 --yes --keyring-backend=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"network": { | ||
"blockchain": "app", | ||
"network": "network" | ||
}, | ||
"online_url": "http://rosetta:8080", | ||
"data_directory": "", | ||
"http_timeout": 300, | ||
"max_retries": 5, | ||
"retry_elapsed_time": 0, | ||
"max_online_connections": 0, | ||
"max_sync_concurrency": 0, | ||
"tip_delay": 60, | ||
"log_configuration": true, | ||
"construction": { | ||
"offline_url": "http://rosetta:8080", | ||
"max_offline_connections": 0, | ||
"stale_depth": 0, | ||
"broadcast_limit": 0, | ||
"ignore_broadcast_failures": false, | ||
"clear_broadcasts": false, | ||
"broadcast_behind_tip": false, | ||
"block_broadcast_limit": 0, | ||
"rebroadcast_all": false, | ||
"constructor_dsl_file": "staking.ros", | ||
"end_conditions": { | ||
"staking": 3 | ||
} | ||
} | ||
} |
Oops, something went wrong.