mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Contract changes (#396)
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal 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
1
examples/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
example_contract
|
||||
1
examples/c_contract/.gitignore
vendored
1
examples/c_contract/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
rnd_contract
|
||||
1
examples/hp-c-contract
Submodule
1
examples/hp-c-contract
Submodule
Submodule examples/hp-c-contract added at a04760f4b8
@@ -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.")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user