Skip to content

Commit

Permalink
Merge pull request #4 from okp4/ci/shellcheck
Browse files Browse the repository at this point in the history
Ci/shellcheck
  • Loading branch information
ccamel authored Oct 6, 2023
2 parents bacc959 + 46e65fa commit af10909
Show file tree
Hide file tree
Showing 28 changed files with 186 additions and 93 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Lint

on:
push:
branches: [ main ]
branches: [main]

pull_request:
branches: [ main ]
branches: [main]

workflow_dispatch:

Expand Down Expand Up @@ -42,6 +42,20 @@ jobs:
- name: Lint yaml files
uses: ibiqlik/action-yamllint@v3.1.1

lint-shell:
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Lint shell scripts
uses: ludeeus/action-shellcheck@2.0.0
with:
scandir: "."
version: "v0.9.0"
env:
SHELLCHECK_OPTS: -x -e SC2002

lint-branch-name:
runs-on: ubuntu-22.04
if: github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')
Expand Down
7 changes: 5 additions & 2 deletions account/10_get_instanciated_contract_address.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

set -euo pipefail

# change the hash 4DB4644E6146DE0E7239C5273F79C931193F542D62979ACB907C9368A315DCE1 to get information from an instantitate transaction
okp4d query tx CB200354719B58A990A077337686CFAF64E95893037AF599DABC2E3B72297FD9 \
--node https://api.testnet.okp4.network:443/rpc \
--output json | jq '.logs[0].events[] | select(.type == "instantiate").attributes[] | select(.key == "_contract_address").value'
--node https://api.testnet.okp4.network:443/rpc \
--output json | jq '.logs[0].events[] | select(.type == "instantiate").attributes[] | select(.key == "_contract_address").value'
15 changes: 9 additions & 6 deletions account/11_execute_sc_example.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash

set -euo pipefail

# insert "Hello OKP4 Builders" in a objectarium instance (okp41tca04wdta7pyzzyetgqyl2rn9v5vgxq0cwvdduel8sgw4g64at7q8jja85)
# execute a 'store_object' message, see https://docs.okp4.network/contracts/okp4-objectarium#executemsgstoreobject
# replace mywallet by your wallet name
echo "Hello OKP4 Builders" > text-ex.txt && \
okp4d tx wasm execute okp41tca04wdta7pyzzyetgqyl2rn9v5vgxq0cwvdduel8sgw4g64at7q8jja85 \
--from mywallet \
--gas 1000000 \
--chain-id okp4-nemeton-1 --node https://api.testnet.okp4.network:443/rpc \
"{\"store_object\":{\"data\": \"$(cat text-ex.txt | base64 | tr -d '\n\r')\", \"pin\":true}}"
echo "Hello OKP4 Builders" >text-ex.txt &&
okp4d tx wasm execute okp41tca04wdta7pyzzyetgqyl2rn9v5vgxq0cwvdduel8sgw4g64at7q8jja85 \
--from mywallet \
--gas 1000000 \
--chain-id okp4-nemeton-1 --node https://api.testnet.okp4.network:443/rpc \
"{\"store_object\":{\"data\": \"$(cat text-ex.txt | base64 | tr -d '\n\r')\", \"pin\":true}}"
14 changes: 8 additions & 6 deletions account/12_query_sc_example.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash

set -euo pipefail

# object_data query message to an objectarium instance (okp41tca04wdta7pyzzyetgqyl2rn9v5vgxq0cwvdduel8sgw4g64at7q8jja85, id = 71f9954abebbd23da1664914cd599f8039585fa3d81735b4abe20893abd32213)
# see https://docs.okp4.network/contracts/okp4-objectarium#querymsgobjectdata
okp4d query wasm contract-state smart okp41tca04wdta7pyzzyetgqyl2rn9v5vgxq0cwvdduel8sgw4g64at7q8jja85 \
--output json \
--chain-id okp4-nemeton-1 \
--node https://api.testnet.okp4.network:443/rpc \
"{\"object_data\": {\"id\":\"71f9954abebbd23da1664914cd599f8039585fa3d81735b4abe20893abd32213\"}}" \
| jq '.data' | tr -d '"' | base64 -d

--output json \
--chain-id okp4-nemeton-1 \
--node https://api.testnet.okp4.network:443/rpc \
"{\"object_data\": {\"id\":\"71f9954abebbd23da1664914cd599f8039585fa3d81735b4abe20893abd32213\"}}" |
jq '.data' | tr -d '"' | base64 -d
3 changes: 3 additions & 0 deletions account/1a_import_wallet.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

set -euo pipefail

# Import from a mnemonic. You can replace "mywallet" with another wallet name
# You must have $KNOW tokens to send a transaction - grab test tokens here: https://faucet.okp4.network/
okp4d keys add --recover mywallet
3 changes: 3 additions & 0 deletions account/1b_create_new_wallet.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

set -euo pipefail

# Create a new wallet. You can replace "mywallet" with another wallet name
# You must have $KNOW tokens to send a transaction - grab test tokens here: https://faucet.okp4.network/
okp4d keys add mywallet
3 changes: 3 additions & 0 deletions account/2_show wallet.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

set -euo pipefail

# Replace "mywallet" with your wallet name
okp4d keys show mywallet
5 changes: 4 additions & 1 deletion account/3_get_balance.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

set -euo pipefail

# Replace "okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5" with your wallet address
okp4d query bank balances okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--node https://api.testnet.okp4.network:443/rpc
--node https://api.testnet.okp4.network:443/rpc
5 changes: 4 additions & 1 deletion account/4_get_total_supply.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/bin/bash

set -euo pipefail

okp4d query bank total \
--node https://api.testnet.okp4.network:443/rpc
--node https://api.testnet.okp4.network:443/rpc
7 changes: 5 additions & 2 deletions account/5_send_tokens.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

set -euo pipefail

# Replace "mywallet" with your wallet name and okp41r0pf2d78w8w29sm9a6qm8x6yqshezm0k6vwcrg to change the receiver address
okp4d tx bank send mywallet okp41r0pf2d78w8w29sm9a6qm8x6yqshezm0k6vwcrg \
500000uknow \
--chain-id okp4-nemeton-1 --node https://api.testnet.okp4.network:443/rpc
500000uknow \
--chain-id okp4-nemeton-1 --node https://api.testnet.okp4.network:443/rpc
7 changes: 5 additions & 2 deletions account/6_get_tx_info.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

set -euo pipefail

# change the hash 4DB4644E6146DE0E7239C5273F79C931193F542D62979ACB907C9368A315DCE1 to get information for another transaction
okp4d query tx 4DB4644E6146DE0E7239C5273F79C931193F542D62979ACB907C9368A315DCE1 \
--node https://api.testnet.okp4.network:443/rpc \
--output json | jq '.tx.body.messages[0]'
--node https://api.testnet.okp4.network:443/rpc \
--output json | jq '.tx.body.messages[0]'
7 changes: 5 additions & 2 deletions account/7_get_events_attributes_tx.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

set -euo pipefail

# change the hash 4DB4644E6146DE0E7239C5273F79C931193F542D62979ACB907C9368A315DCE1 to get information for another transaction
okp4d query tx 4DB4644E6146DE0E7239C5273F79C931193F542D62979ACB907C9368A315DCE1 \
--node https://api.testnet.okp4.network:443/rpc \
--output json | jq '.logs[0].events[] | select(.type == "transfer").attributes'
--node https://api.testnet.okp4.network:443/rpc \
--output json | jq '.logs[0].events[] | select(.type == "transfer").attributes'
11 changes: 7 additions & 4 deletions account/8_filter_tx_example.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash

set -euo pipefail

# Get all transfer transactions where the recipient is okp41r0pf2d78w8w29sm9a6qm8x6yqshezm0k6vwcrg and the amount is 500000uknow
okp4d query txs \
--events 'transfer.recipient=okp41r0pf2d78w8w29sm9a6qm8x6yqshezm0k6vwcrg&transfer.amount=500000uknow' \
--node https://api.testnet.okp4.network:443/rpc \
--page 1 --limit 50 \
--output json | jq '{total_count: .total_count, txs: [.txs[] | {txhash: .txhash, date: .timestamp, txdata: .logs[0].events[] | select(.type == "transfer").attributes}]}'
--events 'transfer.recipient=okp41r0pf2d78w8w29sm9a6qm8x6yqshezm0k6vwcrg&transfer.amount=500000uknow' \
--node https://api.testnet.okp4.network:443/rpc \
--page 1 --limit 50 \
--output json | jq '{total_count: .total_count, txs: [.txs[] | {txhash: .txhash, date: .timestamp, txdata: .logs[0].events[] | select(.type == "transfer").attributes}]}'
16 changes: 9 additions & 7 deletions account/9_instantiate_sc_example.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash

set -euo pipefail

# instantiate an objectarium (code id = 4) smart contract
# see https://docs.okp4.network/contracts/okp4-objectarium#instantiatemsg
# replace okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 with your wallet address
okp4d tx wasm instantiate 4 \
--label "cli-instanciate-test-$(date +%s)" \
--from okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--admin okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--gas 1000000 \
--chain-id okp4-nemeton-1 --node https://api.testnet.okp4.network:443/rpc \
'{"bucket":"cli-tutorial-bucket"}'

--label "cli-instanciate-test-$(date +%s)" \
--from okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--admin okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--gas 1000000 \
--chain-id okp4-nemeton-1 --node https://api.testnet.okp4.network:443/rpc \
'{"bucket":"cli-tutorial-bucket"}'
9 changes: 6 additions & 3 deletions rules/1a_load_inline_rules_query.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

set -euo pipefail

okp4d query logic ask \
--node https://api.testnet.okp4.network:443/rpc \
--program "memberOf(alice, council). memberOf(bob,council). can_vote(X) :- memberOf(X, council)." \
"can_vote(X)."
--node https://api.testnet.okp4.network:443/rpc \
--program "memberOf(alice, council). memberOf(bob,council). can_vote(X) :- memberOf(X, council)." \
"can_vote(X)."
9 changes: 6 additions & 3 deletions rules/1b_load_file_rules_query.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

set -euo pipefail

okp4d query logic ask \
--node https://api.testnet.okp4.network:443/rpc \
--program-file my_knowledgebase.pl \
"can_vote(X)."
--node https://api.testnet.okp4.network:443/rpc \
--program-file my_knowledgebase.pl \
"can_vote(X)."
17 changes: 10 additions & 7 deletions rules/2_store_rules.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/bin/bash

set -euo pipefail

# instantiate a law stone (code id = 5) smart contract
# see https://docs.okp4.network/contracts/okp4-law-stone#instantiatemsg
# replace mywallet with your wallet name
okp4d tx wasm instantiate 5 \
--from mywallet \
--label "rules-tutorial-ex-$(date +%s)" \
--no-admin \
--chain-id okp4-nemeton-1 \
--gas 1000000 \
--node https://api.testnet.okp4.network:443/rpc \
"{\"program\":\"$(cat my_knowledgebase.pl | base64 | tr -d '\n\r')\", \"storage_address\": \"okp41lppz4x9dtmccek2m6cezjlwwzup6pdqrkvxjpk95806c3dewgrfq602kgx\"}"
--from mywallet \
--label "rules-tutorial-ex-$(date +%s)" \
--no-admin \
--chain-id okp4-nemeton-1 \
--gas 1000000 \
--node https://api.testnet.okp4.network:443/rpc \
"{\"program\":\"$(cat my_knowledgebase.pl | base64 | tr -d '\n\r')\", \"storage_address\": \"okp41lppz4x9dtmccek2m6cezjlwwzup6pdqrkvxjpk95806c3dewgrfq602kgx\"}"
17 changes: 10 additions & 7 deletions rules/3_get_last_stored_rules.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/bash

set -euo pipefail

okp4d query wasm contract-state smart okp41lppz4x9dtmccek2m6cezjlwwzup6pdqrkvxjpk95806c3dewgrfq602kgx \
--output json \
--chain-id okp4-nemeton-1 \
--node https://api.testnet.okp4.network:443/rpc \
"{\"object_data\": {\"id\": $(okp4d query txs --events 'message.sender=okp41z4ldttn975ku764er2nvtfq47n6n7jfxnkc2k9&instantiate.code_id=5' \
--chain-id okp4-nemeton-1 --node https://api.testnet.okp4.network:443/rpc \
--output json | jq '.txs[-1].logs[-1].events[] | select(.type == "wasm").attributes[] | select(.key == "id").value')}}" \
| jq '.data' | tr -d '"' | base64 -d
--output json \
--chain-id okp4-nemeton-1 \
--node https://api.testnet.okp4.network:443/rpc \
"{\"object_data\": {\"id\": $(okp4d query txs --events 'message.sender=okp41z4ldttn975ku764er2nvtfq47n6n7jfxnkc2k9&instantiate.code_id=5' \
--chain-id okp4-nemeton-1 --node https://api.testnet.okp4.network:443/rpc \
--output json | jq '.txs[-1].logs[-1].events[] | select(.type == "wasm").attributes[] | select(.key == "id").value')}}" |
jq '.data' | tr -d '"' | base64 -d
7 changes: 5 additions & 2 deletions rules/4_query_rules.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

set -euo pipefail

# evaluate a Prolog query
# from rules stored on a specific "law stone" smart contract instance
okp4d query wasm contract-state smart okp41dey5a35ssvfulh2xud3nkwk423fp0t40nga4a8xykx9frmhm6jpqne0alf \
--node https://api.testnet.okp4.network:443/rpc \
"{\"ask\": {\"query\": \"can_vote(X).\"}}"
--node https://api.testnet.okp4.network:443/rpc \
"{\"ask\": {\"query\": \"can_vote(X).\"}}"
7 changes: 5 additions & 2 deletions rules/5_native_prolog_predicates.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

set -euo pipefail

# To get the list of all available predicates,
# you can query the logic module parameters
okp4d --node "https://api.testnet.okp4.network:443/rpc" \
query logic params -ojson \
| jq -r '.params.interpreter.predicates_filter | "whitelist: " + (.whitelist | join(", ")) + "\nblacklist: " + (.blacklist | join(", "))'
query logic params -ojson |
jq -r '.params.interpreter.predicates_filter | "whitelist: " + (.whitelist | join(", ")) + "\nblacklist: " + (.blacklist | join(", "))'
9 changes: 6 additions & 3 deletions rules/6_check_balance_thresold.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash

set -euo pipefail

# Rules & query example from account balace
#
# Prolog program:
Expand All @@ -7,6 +10,6 @@
# bank_balances(Addr, [Unit-Nb]),
# compare(>, Nb, Limit).
okp4d query logic ask \
--node https://api.testnet.okp4.network:443/rpc \
--program "bank_balances_has_sufficient_coin(Addr, Limit, Unit) :- bank_balances(Addr, [Unit-Nb]), compare(>, Nb, Limit)." \
"bank_balances_has_sufficient_coin(okp416rry8kjuzpxezhf4g4lvjk67mkjc95lterek2u, 9899958230, uknow)."
--node https://api.testnet.okp4.network:443/rpc \
--program "bank_balances_has_sufficient_coin(Addr, Limit, Unit) :- bank_balances(Addr, [Unit-Nb]), compare(>, Nb, Limit)." \
"bank_balances_has_sufficient_coin(okp416rry8kjuzpxezhf4g4lvjk67mkjc95lterek2u, 9899958230, uknow)."
7 changes: 5 additions & 2 deletions rules/7_bech32_prolog_use.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

set -euo pipefail

# Want to know the Stargaze (stars) address from an OKP4 one?
# Here is an example to get it from okp416rry8kjuzpxezhf4g4lvjk67mkjc95lterek2u:
okp4d query logic ask \
--node https://api.testnet.okp4.network:443/rpc \
"bech32_address(-(Prefix, Words), okp416rry8kjuzpxezhf4g4lvjk67mkjc95lterek2u), bech32_address(-(stars, Words), StarsEncodedAddr)."
--node https://api.testnet.okp4.network:443/rpc \
"bech32_address(-(Prefix, Words), okp416rry8kjuzpxezhf4g4lvjk67mkjc95lterek2u), bech32_address(-(stars, Words), StarsEncodedAddr)."
17 changes: 10 additions & 7 deletions semantic/1_create_semantic_database.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/bin/bash

set -euo pipefail

# instantiate a cognitarium (code id = 7) smart contract
# see https://docs.okp4.network/contracts/okp4-cognitarium#instantiatemsg
# replace okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 by your wallet address
okp4d tx wasm instantiate 7 \
--from okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--label "ontology-tutorial-ex-$(date +%s)" \
--admin okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--chain-id okp4-nemeton-1 \
--gas 1000000 \
--node https://api.testnet.okp4.network:443/rpc \
"{}"
--from okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--label "ontology-tutorial-ex-$(date +%s)" \
--admin okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--chain-id okp4-nemeton-1 \
--gas 1000000 \
--node https://api.testnet.okp4.network:443/rpc \
"{}"
9 changes: 6 additions & 3 deletions semantic/2_get_addr_from_instanciation.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

set -euo pipefail

# replace with your cognitarium instantiation transaction hash
okp4d query tx E0985541A08D1DCCA4F362DE445E44FB26A3AB374F84F9335B3EFCF247F263DA \
--node https://api.testnet.okp4.network:443/rpc \
--output json \
| jq '.logs[0].events[] | select(.type == "instantiate").attributes[] | select(.key == "_contract_address").value'
--node https://api.testnet.okp4.network:443/rpc \
--output json |
jq '.logs[0].events[] | select(.type == "instantiate").attributes[] | select(.key == "_contract_address").value'
13 changes: 8 additions & 5 deletions semantic/3a_store_semantic_data_turtle.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash

set -euo pipefail

# insert triples from a file in a cognitarium instance (okp41wn625s4jcmvk0szpl85rj5azkfc6suyvf75q6vrddscjdphtve8sug4ars)
# you should replace the smart contract address as you can only insert in a database (cognitarium instance) you created
# execute an 'insert_data' message, see https://docs.okp4.network/contracts/okp4-cognitarium#executemsginsertdata
# replace mywalokp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5let by your wallet address
okp4d tx wasm execute okp41wn625s4jcmvk0szpl85rj5azkfc6suyvf75q6vrddscjdphtve8sug4ars \
--from okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--gas 10000000 \
--node https://api.testnet.okp4.network:443/rpc \
--chain-id okp4-nemeton-1 \
"{\"insert_data\":{\"format\": \"turtle\", \"data\": \"$(cat 03230ce7-d8cb-410e-919e-19c480c1dd75.ttl | base64 | tr -d '\n\r')\"}}"
--from okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--gas 10000000 \
--node https://api.testnet.okp4.network:443/rpc \
--chain-id okp4-nemeton-1 \
"{\"insert_data\":{\"format\": \"turtle\", \"data\": \"$(cat 03230ce7-d8cb-410e-919e-19c480c1dd75.ttl | base64 | tr -d '\n\r')\"}}"
13 changes: 8 additions & 5 deletions semantic/3b_store_semantic_data_nquads.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash

set -euo pipefail

# insert triples from a file in a cognitarium instance (okp41wn625s4jcmvk0szpl85rj5azkfc6suyvf75q6vrddscjdphtve8sug4ars)
# you should replace the smart contract address as you can only insert in a database (cognitarium instance) you created
# execute an 'insert_data' message, see https://docs.okp4.network/contracts/okp4-cognitarium#executemsginsertdata
# replace mywalokp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5let by your wallet address
okp4d tx wasm execute okp41wn625s4jcmvk0szpl85rj5azkfc6suyvf75q6vrddscjdphtve8sug4ars \
--from okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--gas 10000000 \
--node https://api.testnet.okp4.network:443/rpc \
--chain-id okp4-nemeton-1 \
"{\"insert_data\":{\"format\": \"n_quads\", \"data\": \"$(cat nquads_example.nq | base64 | tr -d '\n\r')\"}}"
--from okp41cu9wzlcyyxpek20jaqfwzu3llzjgx34cwnv2v5 \
--gas 10000000 \
--node https://api.testnet.okp4.network:443/rpc \
--chain-id okp4-nemeton-1 \
"{\"insert_data\":{\"format\": \"n_quads\", \"data\": \"$(cat nquads_example.nq | base64 | tr -d '\n\r')\"}}"
Loading

0 comments on commit af10909

Please sign in to comment.