Skip to content

kwilteam/extension-example-math

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extension Deployment Template

This repo contains an example usage of the template for running Kwil extensions using Docker Compose. It uses a sample math extension.

Quickstart

To download the images and run them as containers, run:

make download-and-run

Usage

To use this repo, you will need to install and configure the Kwil CLI. Within the CLI, you will need to configure:

  1. A private key (Ethereum compatible).
  2. A Kwil provider (your locally running node, by default this will be localhost:50051)

Makefile

This repo contains a makefile that with common commands that may be run in this repo. To see all commands, run:

make help

Scripts

This repo also contains scripts which showcase how to interact with the example Kuneiform schema using the Kwil CLI. The examples show how to use basic math functions from the math extension. The script file contains the following functions:

  • deploy: deploys the example schema.
  • add: prompts the user for values to add (in the deployed database)
  • sub: prompts the user for values to subtract (in the deployed database)
  • mul: prompts the user for values to multiply (in the deployed database)
  • div: prompts the user for values to divide (in the deployed database)

To run a script, simply run:

./script.sh deploy

Math Extension

The math extension is an extension that can perform the basic math operations of addition, subtraction, multiplication, and division. It likely has no real applicable use case, other than to show how to build and use extensions.

Initialization

The math extension can be initialized to either round non-integer reulsts up or down. In Kuneiform, this looks like the following:

use math {
    round: "up"
} as math_up;

use math {
    round: "down"
} as math_down;

Invoking a Method

The extension's methods can be called from within an action:

action call_add($num1) public {
    $sum = math_up.add($num1, 2); // adds 2 to the passed value, and returns it as $sum
    // ... the rest of the action ...
} 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published