Added new contract templates (#31)

This commit is contained in:
Chalith Desaman
2024-03-15 17:16:24 +05:30
committed by GitHub
parent 5838ea7fcc
commit 1face50d32
46 changed files with 3860 additions and 73 deletions

View File

@@ -1,2 +0,0 @@
node_modules
index.js

View File

@@ -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=="
}
}
}

View File

@@ -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"
}
}

View File

@@ -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, {

View File

@@ -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.