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

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