Skip to content

Commit

Permalink
Merge branch 'nightly' into blaze/da_mock_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad committed Aug 22, 2023
2 parents 2140707 + 72d7f36 commit 285d5fe
Show file tree
Hide file tree
Showing 47 changed files with 1,194 additions and 904 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
SECONDS=0
while ((SECONDS <= 1200))
do
if curl -f -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov1zdwj8thgev2u3yyrrlekmvtsz4av4tp3m7dm5mx5peejnesga27svq9m72"],"id":1}' http://127.0.0.1:12345; then
if curl -f -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov16m8fxq0x5wc5aw75fx9rus2p7g2l22zf4re72c3m058g77cdjemsavg2ft"],"id":1}' http://127.0.0.1:12345; then
echo "demo-rollup is up"
exit 0
fi
Expand All @@ -179,7 +179,7 @@ jobs:
SECONDS=0
while ((SECONDS <= 300))
do
if curl -f -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov1zdwj8thgev2u3yyrrlekmvtsz4av4tp3m7dm5mx5peejnesga27svq9m72"],"id":1}' http://127.0.0.1:12345 | grep -q 1000; then
if curl -f -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov16m8fxq0x5wc5aw75fx9rus2p7g2l22zf4re72c3m058g77cdjemsavg2ft"],"id":1}' http://127.0.0.1:12345 | grep -q 1000; then
echo "demo-rollup test succeeded"
exit 0
fi
Expand Down
101 changes: 101 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions examples/demo-rollup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ start-existing:

start-new:
@echo "Starting new container: $(CONTAINER_NAME)"
docker run -d --name $(CONTAINER_NAME) --platform linux/amd64 -p 26657:26657 -p 26659:26659 -p $(RPC_PORT):$(RPC_PORT) -p 9090:9090 $(IMAGE_NAME)
docker run -d --name $(CONTAINER_NAME) --platform linux/amd64 -p 26657:26657 -p 26659:26659 -p $(RPC_PORT):$(RPC_PORT) $(IMAGE_NAME)

start-container:
@$(MAKE) check-container-running || { $(MAKE) check-container-exists && $(MAKE) start-existing || $(MAKE) start-new; }
Expand Down Expand Up @@ -94,13 +94,19 @@ build-sov-cli:
cd ../demo-stf && cargo build --bin sov-cli --features=native

test-generate-create-token-tx: check-container-running build-sov-cli
$(SOV_CLI_REL_PATH) generate-transaction-from-json ../test-data/keys/token_deployer_private_key.json Bank ../test-data/requests/create_token.json 0
$(SOV_CLI_REL_PATH) transactions import from-file bank --path ../test-data/requests/create_token.json

test-build-blob-from-create-token: test-generate-create-token-tx
$(SOV_CLI_REL_PATH) make-batch ../test-data/requests/create_token.dat > ../test-data/requests/test_blob.dat
set-rpc-url: build-sov-cli
$(SOV_CLI_REL_PATH) rpc set-url http://localhost:12345

test-create-token: test-build-blob-from-create-token
$(MAKE) submit-txn SERIALIZED_BLOB_PATH=../test-data/requests/test_blob.dat
import-keys: build-sov-cli
$(SOV_CLI_REL_PATH) keys import --nickname DANGER__DO_NOT_USE_WITH_REAL_MONEY --path ../test-data/keys/minter_private_key.json

test-create-token: set-rpc-url test-generate-create-token-tx import-keys
$(SOV_CLI_REL_PATH) rpc submit-batch

remove-insecure-keys: build-sov-cli
$(SOV_CLI_REL_PATH) keys remove by-address sov15vspj48hpttzyvxu8kzq5klhvaczcpyxn6z6k0hwpwtzs4a6wkvqwr57gc

clean-rollup-db:
$(eval path := ./$(shell awk -F'=' '/^path/ {print $$2}' rollup_config.toml | tr -d '[:space:]"\n'))
Expand Down
106 changes: 45 additions & 61 deletions examples/demo-rollup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ This is a demo full node running a simple Sovereign SDK rollup on [Celestia](htt
- [How to Submit Transactions](#how-to-submit-transactions)
- [1. Build `sov-cli`](#1-build-sov-cli)
- [2. Generate the Transaction](#2-generate-the-transaction)
- [3. Bundle the Serialized Transaction](#3-bundle-the-serialized-transaction)
- [4. Submit the Transaction](#4-submit-the-transaction)
- [5. Verify the Token Supply](#5-verify-the-token-supply)
- [3. Submit the Transaction(s)](#3-submit-the-transactions)
- [4. Verify the Token Supply](#4-verify-the-token-supply)
- [Makefile](#makefile)
- [Remote setup](#remote-setup)
- [How to Customize This Example](#how-to-customize-this-example)
Expand Down Expand Up @@ -143,13 +142,10 @@ Main entry point for CLI
Usage: sov-cli <COMMAND>

Commands:
generate-transaction-from-json Serialize a call to a module. This creates a .dat file containing the serialized transaction
submit-transaction Submits transaction to sequencer
publish-batch Tells Sequencer to publish batch
make-batch Combine a list of files generated by GenerateTransaction into a blob for submission to Celestia
util Utility commands
generate-transaction Generate a transaction from the command line
help Print this message or the help of the given subcommand(s)
transactions Generate, sign, and send transactions
keys View and manage keys associated with this wallet
rpc Query the current state of the rollup and send transactions
help Print this message or the help of the given subcommand(s)

Options:
-h, --help Print help
Expand Down Expand Up @@ -229,88 +225,76 @@ Here's an example of a JSON representing the above call:
"to": "sov1zgfpyysjzgfpyysjzgfpyysjzgfpyysjzgfpyysjzgfpyysjzgfqve8h6h",
"coins": {
"amount": 200,
"token_address": "sov1zdwj8thgev2u3yyrrlekmvtsz4av4tp3m7dm5mx5peejnesga27svq9m72"
"token_address": "sov16m8fxq0x5wc5aw75fx9rus2p7g2l22zf4re72c3m058g77cdjemsavg2ft"
}
}
}
```

#### 2. Generate the Transaction

The JSON above is the contents of the file `examples/test-data/requests/transfer.json`. We'll use this transaction as our example for the rest of the tutorial. In order to serialize the transaction JSON to submit to our local Celestia node, we need to perform 2 operations:
The JSON above is the contents of the file `examples/test-data/requests/transfer.json`. We'll use this transaction as our example for the rest of the tutorial. In order to send the transaction, we need to perform 2 operations:

- Serialize the JSON representation of the transaction.
- Bundle serialized transaction files into a blob (since DA layers accept blobs which can contain multiple transactions).
- Import the transaction data into the wallet
- Sign and submit the transaction

Note: we're able to make a `Transfer` call here because we already created the token as part of the sanity check above, using `make test-create-token`.

To generate transactions you can use the `sov-cli generate-transaction-from-json` subcommand, as shown below:
To generate transactions you can use the `transactions import from-file` subcommand, as shown below:

```sh
$ ./target/debug/sov-cli generate-transaction-from-json -h
Serialize a call to a module. This creates a .dat file containing the serialized transaction
$ ./target/debug/sov-cli transactions import from-file -h
Import a transaction from a JSON file at the provided path

Usage: sov-cli generate-transaction-from-json <SENDER_PRIV_KEY_PATH> <MODULE_NAME> <CALL_DATA_PATH> <NONCE>
Usage: sov-cli transactions import from-file <COMMAND>

Arguments:
<SENDER_PRIV_KEY_PATH> Path to the json file containing the private key of the sender
<MODULE_NAME> Name of the module to generate the call. Modules defined in your Runtime are supported. (eg: Bank, Accounts)
<CALL_DATA_PATH> Path to the json file containing the parameters for a module call
<NONCE> Nonce for the transaction
```

For our test, we'll use the test private key located at `examples/test-data/keys/minter_private_key.json`. This private key also corresponds to the address used in the `minter_address` field of the `create_token.json` file. This was the address that `make test-create-token` minted the new tokens to.

Let's go ahead and serialize the transaction:

```bash
$ ./target/debug/sov-cli generate-transaction-from-json ./examples/test-data/keys/minter_private_key.json Bank ./examples/test-data/requests/transfer.json 0
```

Once the above command executes successfully, there will be a file named `./examples/test-data/requests/transfer.dat`:
Commands:
bank Generates a transaction for the `bank` module
sequencer-registry Generates a transaction for the `sequencer_registry` module
election Generates a transaction for the `election` module
value-setter Generates a transaction for the `value_setter` module
accounts Generates a transaction for the `accounts` module
help Print this message or the help of the given subcommand(s)

```bash
$ cat ./examples/test-data/requests/transfer.dat
5ef848746e8d2b9c27ee46210e185dc9f3b690d5cef42a13fb9c336bd40c798210bf7af613997f7af57c9681a242f5fe4121a1539ba4f5f32f14c49f978b990a7b758bf2e7670fafaf6bf0015ce0ff5aa802306fc7e3f45762853ffc37180fe64a0000000001fea6ac5b8751120fb62fff67b54d2eac66aef307c7dde1d394dea1e09e43dd44c800000000000000135d23aee8cb15c890831ff36db170157acaac31df9bba6cd40e7329e608eabd0000000000000000
Options:
-h, --help Print help
```

The above is the hex representation of the serialized transaction.

#### 3. Bundle the Serialized Transaction

After serializing your transactions (just one in this case), you must bundle them into a blob. You can use the `sov-cli make-batch` subcommand:
Let's go ahead and import the transaction into the wallet

```bash
$ ./target/debug/sov-cli make-batch -h
Usage: sov-cli make-batch [PATH_LIST]...

Arguments:
[PATH_LIST]... List of serialized transactions
$ ./target/debug/sov-cli transactions import from-file bank --path ./examples/test-data/requests/transfer.json
Adding the following transaction to batch:
{
"bank": {
"Transfer": {
"to": "sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqrr8r94",
"coins": {
"amount": 200,
"token_address": "sov16m8fxq0x5wc5aw75fx9rus2p7g2l22zf4re72c3m058g77cdjemsavg2ft"
}
}
}
}
```

Use the command below to store the serialized blob in `./examples/test-data/requests/tx_blob`:

```bash
$ ./target/debug/sov-cli make-batch ./examples/test-data/requests/transfer.dat > ./examples/test-data/requests/tx_blob
$ cat ./examples/test-data/requests/tx_blob
01000000b60000005ef848746e8d2b9c27ee46210e185dc9f3b690d5cef42a13fb9c336bd40c798210bf7af613997f7af57c9681a242f5fe4121a1539ba4f5f32f14c49f978b990a7b758bf2e7670fafaf6bf0015ce0ff5aa802306fc7e3f45762853ffc37180fe64a0000000001fea6ac5b8751120fb62fff67b54d2eac66aef307c7dde1d394dea1e09e43dd44c800000000000000135d23aee8cb15c890831ff36db170157acaac31df9bba6cd40e7329e608eabd0000000000000000
```
This output indicates that the wallet has saved the transaction details for later signing.

#### 4. Submit the Transaction
#### 3. Submit the Transaction(s)

You now have a blob with one serialized transaction in `./examples/test-data/requests/tx_blob`. Switch back to the `examples/demo-rollup` directory and use the Makefile to submit it:
You now have a batch with a single transaction in your wallet. If you want to submit any more transactions as part of this
batch, you can import them now. Finally, let's submit your transaction to the rollup.

```bash
$ cd examples/demo-rollup
$ SERIALIZED_BLOB_PATH=../test-data/requests/tx_blob make submit-txn
$ cargo run rpc submit-batch by-address sov15vspj48hpttzyvxu8kzq5klhvaczcpyxn6z6k0hwpwtzs4a6wkvqwr57gc
```

Here the `make submit-txn` command locates the Docker container the Celestia instance is running in, and runs the Celestia-specific command to submit the transaction.
This command will use your default private key

#### 5. Verify the Token Supply
#### 4. Verify the Token Supply

```bash
$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov1zdwj8thgev2u3yyrrlekmvtsz4av4tp3m7dm5mx5peejnesga27svq9m72"],"id":1}' http://127.0.0.1:12345
$ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov16m8fxq0x5wc5aw75fx9rus2p7g2l22zf4re72c3m058g77cdjemsavg2ft"],"id":1}' http://127.0.0.1:12345
{"jsonrpc":"2.0","result":{"amount":1000},"id":1}
```

Expand Down
Loading

0 comments on commit 285d5fe

Please sign in to comment.