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