From 003a9e40fbdd2f4c96aea19b4595f6fc7f8f8fe3 Mon Sep 17 00:00:00 2001 From: Dulana <57042272+du1ana@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:25:08 +0530 Subject: [PATCH] Contract changes (#396) --- .gitmodules | 3 +++ examples/.gitignore | 1 + examples/c_contract/.gitignore | 1 - examples/hp-c-contract | 1 + examples/js_client/file-client.js | 34 ++++++++++++---------------- test/local-cluster/cluster-create.sh | 14 ++++++------ 6 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 .gitmodules create mode 100644 examples/.gitignore delete mode 100644 examples/c_contract/.gitignore create mode 160000 examples/hp-c-contract diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..79a98129 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "examples/hp-c-contract"] + path = examples/hp-c-contract + url = https://github.com/EvernodeXRPL/hp-c-contract.git diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 00000000..c1a6b30d --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1 @@ +example_contract \ No newline at end of file diff --git a/examples/c_contract/.gitignore b/examples/c_contract/.gitignore deleted file mode 100644 index eceb15dd..00000000 --- a/examples/c_contract/.gitignore +++ /dev/null @@ -1 +0,0 @@ -rnd_contract \ No newline at end of file diff --git a/examples/hp-c-contract b/examples/hp-c-contract new file mode 160000 index 00000000..a04760f4 --- /dev/null +++ b/examples/hp-c-contract @@ -0,0 +1 @@ +Subproject commit a04760f4b8c7ca49f2365977accf0cf8f0812b03 diff --git a/examples/js_client/file-client.js b/examples/js_client/file-client.js index d6a481ac..e536be00 100644 --- a/examples/js_client/file-client.js +++ b/examples/js_client/file-client.js @@ -60,30 +60,22 @@ async function main() { else console.log("File " + result.fileName + " delete failed. reason: " + result.status); } + if (result.type == "downloadResult") { + if (result.status == "ok") { + fs.writeFileSync(result.fileName, result.content.buffer); + console.log("File " + result.fileName + " downloaded to current directory."); + } + else { + console.log("File " + result.fileName + " download failed. reason: " + result.status); + } + } else { console.log("Unknown contract output."); + console.log(JSON.stringify(result)); } - }); }) - // This will get fired when contract sends a read response. - hpc.on(HotPocket.events.contractReadResponse, (response) => { - const result = bson.deserialize(response); - if (result.type == "downloadResult") { - if (result.status == "ok") { - fs.writeFileSync(result.fileName, result.content.buffer); - console.log("File " + result.fileName + " downloaded to current directory."); - } - else { - console.log("File " + result.fileName + " download failed. reason: " + result.status); - } - } - else { - console.log("Unknown read request result."); - } - }) - console.log("Ready to accept inputs."); const input_pump = () => { @@ -122,10 +114,14 @@ async function main() { else if (inp.startsWith("download ")) { const fileName = inp.substr(9); - hpc.sendContractReadRequest(bson.serialize({ + const input = await hpc.submitContractInput(bson.serialize({ type: "download", fileName: fileName })); + + const submission = await input.submissionStatus; + if (submission.status != "accepted") + console.log("Download failed. reason: " + submission.reason); } else { console.log("Invalid command. [upload | delete | download ] expected.") diff --git a/test/local-cluster/cluster-create.sh b/test/local-cluster/cluster-create.sh index c7603d76..284a0996 100755 --- a/test/local-cluster/cluster-create.sh +++ b/test/local-cluster/cluster-create.sh @@ -20,14 +20,14 @@ hpcore=$(realpath ../..) iprange="172.1.1" # Contract can be set with 'export CONTRACT='. Defaults to nodejs echo contract. -if [ "$CONTRACT" = "cecho" ]; then # C echo contract - echo "Using C echo contract." - pushd $hpcore/examples/c_contract/ > /dev/null 2>&1 - gcc echo_contract.c -o echo_contract -Wall -Werror - popd > /dev/null 2>&1 - copyfiles="$hpcore/examples/c_contract/echo_contract" - binary="echo_contract" +if [ "$CONTRACT" = "cexample" ]; then # C example contract + echo "Using C example contract." + pushd $hpcore/examples/hp-c-contract/ > /dev/null 2>&1 + gcc example_contract.c -o ../example_contract -Wall -Werror + popd > /dev/null 2>&1 + copyfiles="$hpcore/examples/example_contract" + binary="example_contract" elif [ "$CONTRACT" = "nodefile" ]; then # nodejs file contract (uses BSON protocol) echo "Using nodejs file contract." pushd $hpcore/examples/nodejs_contract/ > /dev/null 2>&1