mirror of
https://github.com/EvernodeXRPL/hp-devkit.git
synced 2026-04-29 15:37:58 +00:00
Added new contract templates (#31)
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
node_modules
|
||||
index.js
|
||||
@@ -1,41 +0,0 @@
|
||||
{
|
||||
"name": "_projname_",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "_projname_",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@vercel/ncc": "0.34.0",
|
||||
"hotpocket-nodejs-contract": "0.5.6"
|
||||
}
|
||||
},
|
||||
"node_modules/@vercel/ncc": {
|
||||
"version": "0.34.0",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz",
|
||||
"integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==",
|
||||
"bin": {
|
||||
"ncc": "dist/ncc/cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/hotpocket-nodejs-contract": {
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/hotpocket-nodejs-contract/-/hotpocket-nodejs-contract-0.5.6.tgz",
|
||||
"integrity": "sha512-Q52cE5lYGoVGvdUl3cDYixAh27QxzFF6JFaOm1+HoXU36dsKxZfDeJLGCfnDf4XcgEytM2mPE9STWUV+mdHqEg=="
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/ncc": {
|
||||
"version": "0.34.0",
|
||||
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz",
|
||||
"integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A=="
|
||||
},
|
||||
"hotpocket-nodejs-contract": {
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/hotpocket-nodejs-contract/-/hotpocket-nodejs-contract-0.5.6.tgz",
|
||||
"integrity": "sha512-Q52cE5lYGoVGvdUl3cDYixAh27QxzFF6JFaOm1+HoXU36dsKxZfDeJLGCfnDf4XcgEytM2mPE9STWUV+mdHqEg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
"start": "npm run build && hpdevkit deploy dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"hotpocket-nodejs-contract": "0.5.10",
|
||||
"hotpocket-nodejs-contract": "^0.7.3",
|
||||
"@vercel/ncc": "0.34.0"
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,23 @@ export class _projname_ {
|
||||
sendOutput; // This function must be wired up by the caller.
|
||||
|
||||
async handleRequest(user, message, isReadOnly) {
|
||||
|
||||
// This sample application defines two simple messages. 'get' and 'set'.
|
||||
// It's up to the application to decide the structure and contents of messages.
|
||||
|
||||
if (message.type == 'get') {
|
||||
if (message.type == 'stat') {
|
||||
|
||||
// Send response as the status.
|
||||
await this.sendOutput(user, {
|
||||
type: 'statResult',
|
||||
data: 'Contract is online'
|
||||
})
|
||||
}
|
||||
else if (message.type == 'get') {
|
||||
|
||||
// Retrieved previously saved data and return to the user.
|
||||
const data = await this.getData();
|
||||
await this.sendOutput(user, {
|
||||
type: 'data_result',
|
||||
type: 'dataResult',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
@@ -26,6 +33,11 @@ export class _projname_ {
|
||||
if (!isReadOnly) {
|
||||
// Save the provided data into storage.
|
||||
await this.setData(message.data);
|
||||
|
||||
await this.sendOutput(user, {
|
||||
type: 'dataResult',
|
||||
data: 'success'
|
||||
})
|
||||
}
|
||||
else {
|
||||
await this.sendOutput(user, {
|
||||
|
||||
@@ -34,7 +34,7 @@ async function contract(ctx) {
|
||||
const buf = await ctx.users.read(input);
|
||||
|
||||
// Let's assume all data buffers for this contract are JSON.
|
||||
// In real-world apps, we need to gracefully fitler out invalid data formats for our contract.
|
||||
// In real-world apps, we need to gracefully filter out invalid data formats for our contract.
|
||||
const message = JSON.parse(buf);
|
||||
|
||||
// Pass the JSON message to our application logic component.
|
||||
|
||||
Reference in New Issue
Block a user