Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: submit script #131

Merged
merged 9 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ To test the project, run:
snforge test
```

## Scripts

### `submit-state-diff`

You must have a Celestia light node for this script.
Follow this [tutorial](https://docs.celestia.org/developers/node-tutorial) to init
a node for the [Mocha testnet](https://docs.celestia.org/nodes/mocha-testnet).

```bash
bash scripts/submit-state-diff.sh
```

## Contributors ✨

We live on contributions. If you'd like to contribute please follow the [guide](CONTRIBUTING.md).
Expand Down
1 change: 0 additions & 1 deletion scripts/request-data-commitments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ NO_SEND=false
VERBOSE=false
WAIT=true


SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
WORK_DIR=$SCRIPT_DIR/..

Expand Down
90 changes: 90 additions & 0 deletions scripts/submit-state-diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
#
# Submit payload to Celestia
# Uses a light node and pre-funded account to submit data
# to Celestia

# Constants
NETWORK="mocha"
AUTH_TOKEN=$(celestia light auth admin --p2p.network $NETWORK)
VERBOSE=false

# Optional
NAMESPACE="SN_APP"
DATA_PATH="src/tests/data/os_output.json"

usage() {
echo "usage: $0 [-n namespace] [-d path] [-v]"
echo -e "\tsubmit data to celestia"
echo
echo -e "\t-n, --namespace celestia Namespace(default: SN_APP)"
echo -e "\t-d, --data-path local path to data for submission"
echo -e "\t-v, --verbose display verbose output"
}

# Transform long options to short ones
for arg in "$@"; do
shift
case "$arg" in
"--namespace") set -- "$@" "-n" ;;
"--data-path") set -- "$@" "-d" ;;
"--verbose") set -- "$@" "-v" ;;
"--help") set -- "$@" "-h" ;;
*) set -- "$@" "$arg"
esac
done

# Parse command line arguments
while getopts ":n:d:vh" opt; do
case ${opt} in
n)
NAMESPACE="${OPTARG}"
;;
d)
DATA_PATH="${OPTARG}"
;;
v)
VERBOSE=true
;;
h)
usage
exit 0
;;
*)
echo "Invalid option: $OPTARG" 1>&2
usage
exit 1
;;
esac
done

# Check Dependencies
if ! command -v celestia > /dev/null; then
echo -e "please install:\n\thttps://docs.celestia.org/developers/node-tutorial"
exit 1
fi

CEL_BALANCE=$(celestia state balance --token $AUTH_TOKEN | jq -r '.result.amount')
if [ ${CEL_BALANCE} -gt 0 ]; then
echo "Celestia Account Balance: $CEL_BALANCE UTIA"
else
echo "Celestia Account: insufficient balance"
exit 1
fi

if [ ! -f $DATA_PATH ]; then
echo "INVALID DATA PATH($DATA_PATH)"
exit 1
fi

# Format and submit data
HEX_NS=0x$(xxd -p <<< $NAMESPACE)
HEX_DATA=$(xxd -p -c 0 $DATA_PATH)
echo "Submission Results:"
CEL_RESPONSE=$(celestia blob submit $HEX_NS $HEX_DATA --token $AUTH_TOKEN)
echo $CEL_RESPONSE | jq

if $VERBOSE; then
HEIGHT=$(echo $CEL_RESPONSE | jq '.result.height')
celestia header get-by-height $HEIGHT --token $AUTH_TOKEN
fi
66 changes: 66 additions & 0 deletions src/tests/data/os_output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
125777881657840305468919655792243043894346744037226223335092204105986408733,
2040334332115293258607805604894929469377060974617729443381753056905784954023,
1,
2535437458273622887584459710067137978693525181086955024571735059458497227738,
310876289256536046287137994578069209749202099665831078341805439700916543594,
5,
2006810680437147719782949677362224138923732654511812452693656965873469983890,
85,
2,
12,
34,
6,
85,
1005161437792794307757078281996005783125378987969285529172328835577592343232,
0,
352040181584456735608515580760888541466059565068553383579463728554843487745,
1,
2,
5,
1005161437792794307757078281996005783125378987969285529172328835577592343232,
340282366920938463463374607431768211462,
692694963414257194264020892248745848197431340753065024006875718260869872089,
123,
456,
300,
2215430303710902791540996484823030809971452078551498009603035870583464052788,
311,
1536727068981429685321,
322,
19,
815679926571212018227195848707562322348558067406060931041239273854107494620,
2,
1316419243995606702889870694869183679645676506242823596326912212936248352465,
3262122051170176624039908867798875903980511552421730070376672653403179864416,
2006810680437147719782949677362224138923732654511812452693656965873469983890,
340282366920938463463374607431768211461,
2084524728099985327606460172540572310995923661656859675449923268913980850263,
85,
47,
321,
543,
444,
666,
1715425246256821823855536409958992540846451989567087551676457027799652256186,
100,
1715425246256821823855536409958992540846451989567087551676457027799652256187,
200,
2221633069513894212967173919871301977519426338681819384231748898933664013766,
340282366920938463463374607431768211460,
3262122051170176624039908867798875903980511552421730070376672653403179864416,
15,
1,
111,
987,
555,
888,
666,
999,
2618767603815038378512366346550627731109766804643583016834052353912473402832,
442721857769029238784,
3302098605493938887217934688678356071939708546668669666319008757914002811976,
340282366920938463463374607431768211456,
3262122051170176624039908867798875903980511552421730070376672653403179864416,
0
]