2.0.1 • Published 5 years ago

propschain-js v2.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

propschain-js

PROPS side chain JS lib

Repo in development in flux expect changes to some API methods until an official 1.0 release is made. Documentation can be found here

dependencies Inline docs Read the Docs

Installation

yarn add propschain-js

Usage

Client

import { props } from 'propschain-js';

// setup config with URI to REST API and private key for signing
const client = new props.Client('http://127.0.0.1:8008', '196749ed808372060eaeffe10e56de82a48829fcf52199847e1e1db4b780ced0');
console.log(client);

Earnings

Issue

import { props } from 'propschain-js';

const client = new props.Client('http://127.0.0.1:8008', '196749ed808372060eaeffe10e56de82a48829fcf52199847e1e1db4b780ced0');

// will create 3 issue transactions and then submit them in the next batch
client
    .earnings.issue('0x99feebb064fd24fa4e274322144a3771fa', '0x99dkfh5364fd24fa4e27432214009988fa', 100, c.signer)
    .earnings.issue('0x99feebb064fd24fa4e274322144a3771fa', '0x99dkfh5364fd24fa4e27432214009988fa', 200, c.signer)
    .earnings.issue('0x99feebb064fd24fa4e274322144a3771fa', '0x99dkfh5364fd24fa4e27432214009988fa', 300, c.signer)
    .submitNextBatch()
    .then(res => console.log(res))
    .catch(err => console.log(err));

Output:

 { link: 'http://localhost:8008/batch_statuses?id=0d92844959044c01502677d57305d545fa1afa3858b1b39ba4a131bbaac2cb4e38ae23df38b0afbd12e9fe1ffe1d5b363c156a86c865d795d33d1944a3882c1e' }

Revoke

import { props } from 'propschain-js';

const client = new props.Client('http://127.0.0.1:8008', '196749ed808372060eaeffe10e56de82a48829fcf52199847e1e1db4b780ced0');

// will revoke 2 of the earnings issued in our Issue example
client
    .earnings.revoke(['0x99feebb064fd24fa4e274322144a3771fa'],'a7db466982d1bd085f591e041e26ae49a1465509acdac60aa945de3c1a29ef2c336561')
    .earnings.revoke(['0x99feebb064fd24fa4e274322144a3771fa'],'a7db466982d1bdeb05e4ad9d89435594892a34b5a4e6c01ff2c7ecefd7e8d67900aa25')
    .submitNextBatch();
    .then(res => console.log(res))
    .catch(err => console.log(err));

Output:

{ link: 'http://localhost:8008/batch_statuses?id=0d92844959044c01502677d57305d545fa1afa3858b1b39ba4a131bbaac2cb4e38ae23df38b0afbd12e9fe1ffe1d5b363c156a86c865d795d33d1944a3882c1e' }

Settle

import { props } from 'propschain-js';

try {
    const client = new props.Client('http://127.0.0.1:8008', '196749ed808372060eaeffe10e56de82a48829fcf52199847e1e1db4b780ced0');
    const recipient = '0x99feebb064fd24fa4e274322144a3771fa';
    const application = '0x01afcedf1cee9fc38cb5f2cb49840e2b27238e1a';

    // this is the ethereum hash that was created when PROPS were transfered from this application to the recipient to cover these earnings. 
    const ethTxHash = '0xb279182d99e65703f0076e4812653aab85fca0f0';

    // first we need to get all the pending earnings for all the earnings issued to the recipient by the application. This is used for our state authorization
    const pendingAddresses = await client.getPendingAddresses(recipient, application);

    // create and submit our settle transaction
    const resp = await client.earnings.settle(ethTxHash, recipient, pendingAddresses).submitNextBatch();
    console.log(resp);
} catch (err) {
    console.log(err);
}

Output:

{ link: 'http://localhost:8008/batch_statuses?id=0d92844959044c01502677d57305d545fa1afa3858b1b39ba4a131bbaac2cb4e38ae23df38b0afbd12e9fe1ffe1d5b363c156a86c865d795d33d1944a3882c1e' }

Events

The subscriber currently only has a method to listen for earnings changes by recipient. More events and configuration will be added in the near future.

import { props } from 'propschain-js';

const subscriber = new props.Subscriber('tcp://localhost:4004');
const onEvent = (e) => {
   console.log(e);
};

const onError = (err) => {
 console.error(err);
};

const onConnect = (subscriber) => {
   subscriber.subscribeAllEarnings();
   subscriber.subscribeBlocks();
}

const subscriber = new props.Subscriber('tcp://localhost:4004', onConnect, onEvent, onError);
subscriber.start()

Output:

Application:  0x99dkfh5364fd24fa4e27432214009988fa
Recipient:  0x99feebb064fd24fa4e274322144a3771fa
Event Type:  EarningIssued
Event:  { earning:
    { details:
       {
          timestamp: 1544461618,
          amountEarned: 100,
          amountSettled: 0,
          recipientPublicAddress: '0x99feebb064fd24fa4e274322144a3771fa',
          applicationPublicAddress: '0x99dkfh5364fd24fa4e27432214009988fa',
          status: 0
        },
      signature: 'd2f641ee307f4db838a825081d88d46d700d05a56bb4e006d6947fad25ea3ece26fe842e16b6a62c1925c1aa00014e4fa05d2055201c651abdd8dcd6f7ab3161',
      settledByTransaction: ''
    },
    message: 'earning issued: a7db466982d1bd089b33fca55c325f0f84aa48c487b5fa58ba6301aabe136f69b7e13b' 
}

State Queries

Earnings

import { props } from 'propschain-js';

const client = new props.Client('http://127.0.0.1:8008', '196749ed808372060eaeffe10e56de82a48829fcf52199847e1e1db4b780ced0');

try {
    const resp = client.stateQuery('a7db466982d1bd089b33fca55c325f0f84aa48c487b5fa58ba6301aabe136f69b7e13b');
    console.log(resp.toEarnings());
} catch (error) {
    console.log(error);
}

Settlements

import { props } from 'propschain-js';

const client = new props.Client('http://127.0.0.1:8008', '196749ed808372060eaeffe10e56de82a48829fcf52199847e1e1db4b780ced0');

try {
    const resp = client.stateQuery('a7db466982d1bd089b33fca55c325f0f84aa48c487b5fa58ba6301aabe136f69b7e13b');
    console.log(resp.toSettlements());
} catch (error) {
    console.log(error);
}
2.0.1

5 years ago

2.0.0

5 years ago

1.5.0

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.7

5 years ago

1.1.5

5 years ago

1.1.3

5 years ago

1.1.1

5 years ago

1.0.7

5 years ago

1.0.5

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago