0.0.3 • Published 4 years ago

aagent.js_test v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

aagent.js

What's it?

It CLI and library for working with aa on Obyte

CLI

Init

npm i -g aagent.js
aagent --help

Create project from template (with example aa, tests and library)

aagent init .

Validating aa

aagent validate aa.oscript

Open GUI Wallet for deploy

aagent deploy aa.oscript

This command supports argument --testnet to deploy script through the testnet or mainnet wallet.

Start tests

yarn test

Library

AA

Example:

require('headless-obyte');
const eventBus = require('ocore/event_bus');

const { AA } = require('aagent.js');

eventBus.on('headless_wallet_ready', () => {
    const aa = new AA('address');

    aa.events.on('new_request', (request) => {
        console.log('new request', request);
    });

    aa.events.on('new_response', (err, response, vars) => {
        console.log('new response', response, vars);
    });

    aa.events.on('new_aa_definition', (definition) => {
        console.log('new aa definition', definition);
    });

    aa.events.on('new_aa_definition_saved', (definition) => {
        console.log('new aa definition saved', definition);
    });

    aa.newResponseFilter((err, params, vars) => {        
        return true;
      }, (err, params, vars) => {
        console.log(err, params, vars);
      });

});

AA class contains the following methods:

All events are applied to the address specified in the constructor.

constructor
const aa = new AA('address')

one argument - aa_address(string)

static method getAAVars:

AA.getAAVars('address');

will return AA from aa.

newRequestFilter
aa.newRequestFilter((request, body) => {
    return true;
  }, (request, body) => {
    console.log(request, body);
  });

A series of data by the method is triggered by events and if the first function returns true, it calls the second function. Other methods from series: More about arguments in events.

aa.newResponseFilter((err, params, vars, body) => {
    return true;
  }, (err, params, vars, body) => {
    console.log(err, params, vars, body);
  });
aa.newDefinitionFilter((definition, body) => {
    return true;
  }, (definition, body) => {
    console.log(definition, body);
  });
aa.newDefinitionSavedFilter((definition, body) => {
    return true;
  }, (definition, body) => {
    console.log(definition, body);
  });

And events:

new_request
aa.events.on('new_request', (request, body) => {
  console.log('new request', request, body);
});

Arguments:

  • request - {address: aa_address, messages: unit.messages}
  • body - raw body from event
new_response
aa.events.on('new_response', (err, params, vars, body) => {
  console.log('new response', err, params, vars, body);
});

Arguments:

  • err - if bounced return error message
  • params - { address: aa_address, response: body.response }
  • vars - new vars from aa
  • body - raw body from event
new_aa_definition
aa.events.on('new_aa_definition', (definition, body) => {
  console.log('new aa definition', definition, body);
});

Arguments:

  • definition - definition from messages
  • body - raw body from event
new_aa_definition_saved
aa.events.on('new_aa_definition_saved', (definition, body) => {
  console.log('new aa definition saved', definition, body);
});

Arguments:

  • definition - definition from messages
  • body - raw body from event

AAs

All events apply to the addresses specified in the constructor.

constructor
const aas = new AAs(['address'])

one argument - aa_addresses - arraystring

aas.addAddress('address');

Adds a new address and subscribes to it

static method getAAVars:

AAs.getAAVars('address');

will return AA from aa.

This class only supports: Methods: newRequestFilter, newResponseFilter Events: new_request, new_response Arguments are identical to class AA

If you want to start developing on Obyte and you need help, write to us on discord or on telegram: @xJeneK

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago