Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Functional Options #15

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
76 changes: 49 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,75 @@ yarn add wavelet-client
## Usage

```javascript
const {Wavelet, Contract, TAG_TRANSFER} = require('..');
const { Wavelet, Contract, TAG_TRANSFER, SetOption } = require('wavelet-client');

const JSBI = require('jsbi');
const BigInt = JSBI.BigInt;

const client = new Wavelet("http://127.0.0.1:9000");
const client = new Wavelet('https://testnet.perlin.net');

(async () => {
console.log(await client.getNodeInfo());

console.log(await client.getAccount('400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405'));

const transfer = await client.getTransaction('805e4ff2a9955b804e32579166c8a54e07e3f1c161702254d8778e4805ea12fc');
console.log(Wavelet.parseTransaction(transfer.tag, transfer.payload));
try {
const transfer = await client.getTransaction('9eba6ea46d551c60af17837a29a472680043fdf6c9b5de16beb33b3b1b569660');
console.log(Wavelet.parseTransaction(Wavelet.Tag(transfer.tag), Wavelet.payload(transfer.payload)));

const call = await client.getTransaction('9a8746b7bf7a84af7fbd41520a841e96907bee71a88560af7e6996cfb7682891');
console.log(Wavelet.parseTransaction(call.tag, call.payload));
const call = await client.getTransaction('42ec15463eb14d93a63960ade358d15554cb3c6d733670a7e69b96c6f3ec69b4');
console.log(Wavelet.parseTransaction(Wavelet.Tag(call.tag), Wavelet.payload(transfer.payload)));

const stake = await client.getTransaction('673ef140f8a47980d8684a47bf639624d7a4d8470ad30c1a66a4f417f69ab84a');
console.log(Wavelet.parseTransaction(stake.tag, stake.payload));
const stake = await client.getTransaction('5fe8bac3b084c568bf49397333034dcc1d6818756da470fcb3675b95eee68bcd');
console.log(Wavelet.parseTransaction(Wavelet.Tag(stake.tag), Wavelet.payload(transfer.payload)));

} catch (err) {
console.error(err);
}

const wallet = Wavelet.loadWalletFromPrivateKey('87a6813c3b4cf534b6ae82db9b1409fa7dbd5c13dba5858970b56084c4a930eb400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405');
const account = await client.getAccount(Buffer.from(wallet.publicKey).toString("hex"));
const account = await client.getAccount(Buffer.from(wallet.publicKey).toString('hex'));

const contract = new Contract(client, '52bb52e0440ce0aa7a7d2018f5bac21d6abde64f5b9498615ce2bef332bd487a');
console.log(account);

const contract = new Contract(client, Contract.ContractId('61820bc6796380c12347f69be171868b4e268204caa76ab68087cbde4f925beb'));
await contract.init();

console.log(contract.test(wallet, 'balance', BigInt(0),
{
type: 'raw',
value: '400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405'
},
));
console.log(contract);

const params = [
Contract.Raw('400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405')
];

const gasLimit = JSBI.subtract(BigInt(account.balance), BigInt(1000000));
const testResult = contract.test(
wallet,
'balance',
SetOption('amount', BigInt(0)),
Contract.Params(params)
);

console.log(testResult);

const callResult = await contract.call(
wallet,
'balance',
Contract.Amount(0),
Contract.GasLimit(gasLimit),
Contract.GasDeposit(0),
Contract.Params(params)
);

console.log(await contract.call(wallet, 'balance', BigInt(0), BigInt(0), JSBI.subtract(BigInt(account.balance), BigInt(1000000)),
{
type: 'raw',
value: '400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405'
},
));
console.log(callResult);

const consensusPoll = await client.pollConsensus({onRoundEnded: console.log});
const transactionsPoll = await client.pollTransactions({onTransactionApplied: console.log}, {tag: TAG_TRANSFER, creator: "400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405"});
const accountsPoll = await client.pollAccounts({onAccountUpdated: console.log}, {id: "400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405"});
const consensusPoll = await client.pollConsensus(Wavelet.RoundEnded(console.log));
const transactionsPoll = await client.pollTransactions(Wavelet.TransactionApplied(console.log), Wavelet.Tag(TAG_TRANSFER), Wavelet.Creator('400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405'));
const accountsPoll = await client.pollAccounts(Wavelet.AccountUpdated(console.log), Wavelet.Id('400056ee68a7cc2695222df05ea76875bc27ec6e61e8e62317c336157019c405'));

for (let i = 0; i < 100; i++) {
await client.transfer(wallet, 'e49e8be205a00edb45de8183a4374e362efc9a4da56dd7ba17e2dd780501e49f', BigInt(1000000));
await client.transfer(wallet,
'e49e8be205a00edb45de8183a4374e362efc9a4da56dd7ba17e2dd780501e49f',
Contract.Amount(1000)
);
}
})();
```
Loading