Contract changes (#396)

This commit is contained in:
Dulana
2024-09-09 12:25:08 +05:30
committed by GitHub
parent dec1bdde0b
commit 003a9e40fb
6 changed files with 27 additions and 27 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "examples/hp-c-contract"]
path = examples/hp-c-contract
url = https://github.com/EvernodeXRPL/hp-c-contract.git

1
examples/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
example_contract

View File

@@ -1 +0,0 @@
rnd_contract

View File

@@ -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 <local path> | delete <filename> | download <filename>] expected.")

View File

@@ -20,14 +20,14 @@ hpcore=$(realpath ../..)
iprange="172.1.1"
# Contract can be set with 'export CONTRACT=<name>'. 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