Compare commits
190 Commits
datastruct
...
master
Author | SHA1 | Date |
---|---|---|
nico | 18da2be63d | 8 months ago |
Ganesha Upadhyaya | d580e4a659 | 2 years ago |
Ganesha Upadhyaya | 5eddd0feb2 | 2 years ago |
Artem | 71304c22ad | 2 years ago |
Ganesha Upadhyaya | 3c7061887f | 4 years ago |
Ganesha Upadhyaya | e3d04c6383 | 4 years ago |
Ganesha Upadhyaya | 0c7337918d | 4 years ago |
Ganesha Upadhyaya | e364c4ffea | 4 years ago |
Aaron Li | baaa09e41f | 4 years ago |
Aaron Li | f29f2586dd | 4 years ago |
Isaac Adams | 87d5f999ab | 4 years ago |
Isaac Adams | 42d6400ee1 | 4 years ago |
Isaac Adams | 75a7118e1b | 4 years ago |
vinyl704 | 9d13ab257c | 4 years ago |
dependabot[bot] | 21be4e3fe3 | 4 years ago |
Ganesha Upadhyaya | 99a827782f | 4 years ago |
Ganesha Upadhyaya | 2acbadf97a | 4 years ago |
Sebastian Johnsson | 99bd7ad3d5 | 4 years ago |
Ganesha Upadhyaya | a60117ceac | 4 years ago |
Ganesha Upadhyaya | 4099a321f3 | 4 years ago |
dependabot[bot] | 6ab7227ef3 | 4 years ago |
Ganesha Upadhyaya | 8f8e17fdae | 4 years ago |
Ganesha Upadhyaya | 2762c8edbf | 4 years ago |
Ganesha Upadhyaya | 2a3ad781b6 | 4 years ago |
Ganesha Upadhyaya | aea4ca0cc7 | 4 years ago |
Ganesha Upadhyaya | 13c0830916 | 4 years ago |
Ganesha Upadhyaya | a7979a569f | 4 years ago |
Ganesha Upadhyaya | 1b6e351aa8 | 4 years ago |
PeekPI | 6e2c1e7653 | 4 years ago |
peekpi | d5feeb8d78 | 4 years ago |
peekpi | 4261bc15bb | 4 years ago |
peekpi | 9aefc978f6 | 4 years ago |
peekpi | 95453ee2e7 | 4 years ago |
Ganesha Upadhyaya | caa57d360d | 4 years ago |
Ganesha Upadhyaya | bc2d3a6e8d | 4 years ago |
Ganesha Upadhyaya | 73b97c7d07 | 4 years ago |
Ganesha Upadhyaya | cc4872a9f9 | 4 years ago |
Ganesha Upadhyaya | c6fbf597a5 | 4 years ago |
Ganesha Upadhyaya | 995f6b8f40 | 4 years ago |
Ganesha Upadhyaya | 6bcac8640e | 4 years ago |
PeekPI | cdf471b830 | 4 years ago |
lixp | f0e8056f84 | 4 years ago |
lixp | 1b977860ad | 4 years ago |
PeekPI | 93393dc36c | 4 years ago |
Ganesha Upadhyaya | aaf148c1af | 4 years ago |
dependabot[bot] | f125047487 | 4 years ago |
dependabot[bot] | e4f72e293e | 4 years ago |
dependabot[bot] | 1c47f9c713 | 4 years ago |
Ganesha Upadhyaya | 85e0e76dc0 | 4 years ago |
Ganesha Upadhyaya | 7a8c0f9699 | 4 years ago |
Ganesha Upadhyaya | cda12363c9 | 4 years ago |
Ganesha Upadhyaya | fb2fe2925b | 4 years ago |
lixp | a7e248a433 | 4 years ago |
PeekPI | 08d8f5aaf4 | 4 years ago |
lixp | fd2481aa35 | 4 years ago |
lixp | cf6fd13b86 | 4 years ago |
PeekPI | 794a590238 | 4 years ago |
PeekPI | cc4df6b24e | 4 years ago |
dependabot[bot] | 43eb47107a | 4 years ago |
dependabot[bot] | 2a118ebb7f | 4 years ago |
dependabot[bot] | c8e1e7503c | 4 years ago |
dependabot[bot] | a81045946a | 4 years ago |
dependabot[bot] | 26e38e9e35 | 4 years ago |
Ganesha Upadhyaya | c49abc5691 | 4 years ago |
Ganesha Upadhyaya | ca83e5477c | 4 years ago |
Sebastian Johnsson | 14fb03f3f2 | 4 years ago |
lixp | 40e0db00c5 | 4 years ago |
lixp | 4e111973b9 | 4 years ago |
Dennis Won | 463cfdfb68 | 4 years ago |
Dennis Won | 4033b3f971 | 4 years ago |
Dennis Won | 018c2626fe | 4 years ago |
Dennis Won | b63aae6bfb | 4 years ago |
Ganesha Upadhyaya | aa1b811830 | 4 years ago |
Jong Hyuck Won | 2a1bcbbbbb | 4 years ago |
Dennis Won | e571c4bedc | 4 years ago |
Jong Hyuck Won | d34f347e9e | 4 years ago |
Dennis Won | b6a9e4cc85 | 4 years ago |
lixp | 6a0163eef4 | 4 years ago |
Ganesha Upadhyaya | 7dd958349b | 4 years ago |
lixp | 9aa0985993 | 4 years ago |
lixp | 7d5e968ce1 | 4 years ago |
Ganesha Upadhyaya | 17bcd47f37 | 4 years ago |
Ganesha Upadhyaya | 8bced38228 | 4 years ago |
Hiro | 084bcbb5db | 4 years ago |
Ganesha Upadhyaya | 8136549b75 | 4 years ago |
Ganesha Upadhyaya | 15c4b11502 | 4 years ago |
kraikov | 059e067b23 | 4 years ago |
Hirokryptor | 3bfe0deb4e | 4 years ago |
lixp | 0bf2f24333 | 4 years ago |
Ganesha Upadhyaya | 3f6005764d | 4 years ago |
Ganesha Upadhyaya | cb45ce9744 | 4 years ago |
Ganesha Upadhyaya | 76661bf654 | 4 years ago |
Ganesha Upadhyaya | 802beb1898 | 4 years ago |
Ganesha Upadhyaya | e26885932f | 4 years ago |
kraikov | 6043cafe3e | 4 years ago |
kraikov | b17cedfa1a | 4 years ago |
Ganesha Upadhyaya | 1878e7a2c9 | 4 years ago |
Ganesha Upadhyaya | 0575f19c15 | 4 years ago |
Ganesha Upadhyaya | 03206de34d | 4 years ago |
Ganesha Upadhyaya | 4ebe736137 | 4 years ago |
raptor1001 | 2d6d151f36 | 4 years ago |
Raptor | 1aa1736a2b | 4 years ago |
Ganesha Upadhyaya | 074a3db5d9 | 4 years ago |
Ganesha Upadhyaya | 736625c177 | 4 years ago |
Ganesha Upadhyaya | ebb16df6cb | 4 years ago |
Ganesha Upadhyaya | 7bdf2c0dca | 4 years ago |
Ganesha Upadhyaya | 24876f57a5 | 4 years ago |
coolcottontail | bf83596c22 | 4 years ago |
Raptor | c7fd30ec3f | 4 years ago |
neeboo | bbcb1af037 | 5 years ago |
Ganesha Upadhyaya | f90792fd91 | 5 years ago |
PeekPI | ab95524bd0 | 5 years ago |
Ganesha Upadhyaya | a35db780ae | 5 years ago |
Ganesha Upadhyaya | 56606e9365 | 5 years ago |
neeboo | 4dff73db61 | 5 years ago |
Ganesha Upadhyaya | 87c8df983a | 5 years ago |
Jong Hyuck Won | 0e1a4ba6e5 | 5 years ago |
Ganesha Upadhyaya | a5b0bf7d0f | 5 years ago |
Ganesha Upadhyaya | f0c1c5ed9b | 5 years ago |
Ganesha Upadhyaya | f4f645b639 | 5 years ago |
Leo Chen | ce39d112f3 | 5 years ago |
Wen Zhang | 4217f89fdf | 5 years ago |
Wen Zhang | 70311ff629 | 5 years ago |
Wen Zhang | 7ed3b6d8b7 | 5 years ago |
Wen Zhang | 3411de5cf8 | 5 years ago |
Wen Zhang | 95474d74fe | 5 years ago |
Wen Zhang | 61a8b8e7c0 | 5 years ago |
Wen Zhang | 40fc994fae | 5 years ago |
Wen Zhang | 1d37b68d79 | 5 years ago |
Wen Zhang | 2d637dede9 | 5 years ago |
Wen Zhang | fddea85f1f | 5 years ago |
Wen Zhang | 47672bcd68 | 5 years ago |
Wen Zhang | a9e825f0e3 | 5 years ago |
Wen Zhang | ff6c207e9e | 5 years ago |
Wen Zhang | bb9a818295 | 5 years ago |
Dennis Won | bdcfbf0f80 | 5 years ago |
Dennis Won | 3c7e080a7d | 5 years ago |
Dennis Won | 6547152ba6 | 5 years ago |
Dennis Won | 2d2effaade | 5 years ago |
Dennis Won | 9879a43b16 | 5 years ago |
Jong Hyuck Won | 51d46f22a0 | 5 years ago |
Dennis Won | 5c3397dcea | 5 years ago |
Dennis Won | 7aef8792e5 | 5 years ago |
Dennis Won | ad4f5695d9 | 5 years ago |
Dennis Won | 03f996a9c2 | 5 years ago |
Dennis Won | 09cdf36fe2 | 5 years ago |
neeboo | f5c958460e | 5 years ago |
Matt Lockyer | c5b154ed2b | 5 years ago |
Matt Lockyer | 6d85dbf4ef | 5 years ago |
neeboo | bb018ad93d | 5 years ago |
neeboo | 0ff928bc62 | 5 years ago |
neeboo | 9dc33eca47 | 5 years ago |
Minh Doan | 7b70d4d6b1 | 5 years ago |
neeboo | 244230cd46 | 5 years ago |
neeboo | b4e6a94e72 | 5 years ago |
neeboo | 9e05298fe7 | 5 years ago |
neeboo | db8e2f260b | 5 years ago |
neeboo | 611ff25d74 | 5 years ago |
neeboo | 9d9f15be63 | 5 years ago |
neeboo | 4995796682 | 5 years ago |
neeboo | cc00c23e9a | 5 years ago |
neeboo | a65dafd1dd | 5 years ago |
neeboo | 13b958e005 | 5 years ago |
neeboo | f89b6ce146 | 5 years ago |
Ganesha Upadhyaya | d1f465ee94 | 5 years ago |
Minh Doan | aeb46de5a5 | 5 years ago |
Minh Doan | 93a8e5798d | 5 years ago |
Minh Doan | f47ffc4a5e | 5 years ago |
neeboo | 4338ffd6c1 | 5 years ago |
neeboo | 7b7eb6eb25 | 5 years ago |
neeboo | c5ac2aeba2 | 5 years ago |
Minh Doan | 824fa7602b | 5 years ago |
Minh Doan | 1560ec9dd2 | 5 years ago |
neeboo | da865e3dc8 | 5 years ago |
neeboo | 338b986cec | 5 years ago |
Minh Doan | 287138bc27 | 5 years ago |
neeboo | d70b4c5f0d | 5 years ago |
neeboo | 57296456c9 | 5 years ago |
Minh Doan | 44f222f381 | 5 years ago |
Minh Doan | e369a9fac2 | 5 years ago |
neeboo | d63ffa38a1 | 5 years ago |
neeboo | 0320edd059 | 5 years ago |
neeboo | 27bce049c8 | 5 years ago |
neeboo | 0081f5134e | 5 years ago |
neeboo | 661c168240 | 5 years ago |
Minh Doan | 63350c8af4 | 5 years ago |
Minh Doan | 844d2a41d4 | 5 years ago |
Minh Doan | 420a3fe498 | 5 years ago |
neeboo | 591686a5ce | 5 years ago |
neeboo | b9d880ee05 | 5 years ago |
@ -1,5 +0,0 @@ |
||||
GENESIS_PRIV_KEY=45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e |
||||
HTTP_PROVIDER=http://localhost:9500 |
||||
CHAIN_TYPE=hmy |
||||
CHAIN_ID=2 |
||||
|
@ -0,0 +1,70 @@ |
||||
# Release Guidelines |
||||
## Before Release |
||||
1. Build source first |
||||
```bash |
||||
yarn build:ts |
||||
``` |
||||
2. Run unit tests |
||||
```bash |
||||
yarn test:src |
||||
``` |
||||
3. Run e2e tests |
||||
```bash |
||||
yarn test:e2e |
||||
``` |
||||
4. Clean and build bundle |
||||
```bash |
||||
yarn dist |
||||
``` |
||||
## Publish to npm using `dev:publish` |
||||
|
||||
The packages is to be published to npm, using `@next` tag using script in `package.json` |
||||
|
||||
Follow steps below to publish a npm verion using `@next` tag |
||||
|
||||
1. Commit all changes to github master |
||||
2. Run publish script |
||||
|
||||
```bash |
||||
yarn dev:publish |
||||
``` |
||||
|
||||
3. Select version and confirm all prompts with `Y` |
||||
4. See version changes in `npmjs.com` |
||||
|
||||
This will not change the release version of current npm packages(currently 0.0.7), developers have to use `@next` to install from npm. |
||||
|
||||
For example. |
||||
|
||||
```bash |
||||
npm install @woop-js/core@next |
||||
``` |
||||
|
||||
|
||||
|
||||
## Publish to npm with `lerna` |
||||
|
||||
Follow steps below to publish a npm verion with latest version |
||||
|
||||
1. Commit all changes to github master |
||||
2. Run `lerna publish`, `lerna` is required globally. |
||||
|
||||
```bash |
||||
lerna publish |
||||
``` |
||||
3. Select version and confirm all prompts with `Y` |
||||
4. See version changes in `npmjs.com` |
||||
|
||||
This will change the release version of current npm packages to the latest version, developers can install from npm directly |
||||
|
||||
For example. |
||||
|
||||
```bash |
||||
npm install @woop-js/core |
||||
``` |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,100 @@ |
||||
# Woop JS-SDK Documentation |
||||
|
||||
## [CLICK ME!!](https://woop-js-sdk-doc.s3-us-west-1.amazonaws.com/index.html) to see the documentation |
||||
|
||||
# metaDocumentation |
||||
## Summary |
||||
The following content demonstrate how to generate our documentation! |
||||
|
||||
## Step 1: Generate Documentation |
||||
|
||||
### Introduction of TypeDoc |
||||
[TypeDoc is used to generate HTML](https://typedoc.org/api/index.html) |
||||
> See [TypeDoc command line arguments](https://typedoc.org/guides/options/), to understand how to use them. |
||||
> Using `typedoc --help` to see them |
||||
> |
||||
> **For example:** |
||||
> `typedoc --name <Name>` to set the name of header |
||||
> `typedoc --theme <default | minimal | path/to/theme>` to set the theme of documation |
||||
> `typedoc --readme <path/to/readme | none>` path to readme file that should be displayed on the index page. |
||||
> `typedoc --ignoreCompilerErrors` Should TypeDoc generate documentation pages even after the compiler has returned errors? |
||||
|
||||
### Install TypeDoc |
||||
Local installation (prefered) |
||||
``` |
||||
$ npm install typedoc --save-dev |
||||
``` |
||||
|
||||
Golbal CLI installation |
||||
``` |
||||
$ npm install --global typedoc |
||||
``` |
||||
|
||||
### Install Environemnt |
||||
``` |
||||
$ npm install |
||||
``` |
||||
|
||||
### Generate HTML |
||||
``` |
||||
$ cd docs |
||||
$ npx typedoc --out ./build ../packages/ --ignoreCompilerErrors --theme default --name Woop_SDK_Doc --readme ../README.md |
||||
``` |
||||
|
||||
### See the generated doc at local |
||||
|
||||
>open the `index.html` under the path `sdk/docs/build/index.html` |
||||
|
||||
## Step 2: Deploy on AWS (woop core only!) |
||||
|
||||
### Create an AWS s3 bucket |
||||
Actually, there are just two points needed! |
||||
1. Create an AWS S3 bucket, **UNCHECK** `Block all public access` |
||||
2. Put the files into the bucket, and set the **public permission** to `Grant public read access to this object(s)` |
||||
|
||||
### Method 1: Use Console |
||||
|
||||
[Here](https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html) is the documentation of AWS, just follow it! |
||||
|
||||
>Don't forget the two points mentioned above |
||||
|
||||
### Method 2: Use AWS CLI |
||||
|
||||
Reference: [AWS CLI documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html) |
||||
|
||||
If you have never used AWS CLI, you need follow these to set up your environment first! |
||||
- [Install the AWS CLI version 1](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html) |
||||
- [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) |
||||
|
||||
After that, use AWS CLI to do following |
||||
|
||||
1. Create a Bucket |
||||
``` |
||||
aws s3 mb s3://woop-js-sdk-doc |
||||
``` |
||||
|
||||
2. List all buckets you have created |
||||
``` |
||||
aws s3 ls |
||||
``` |
||||
|
||||
3. Uploade the files into bucket |
||||
``` |
||||
$ cd build |
||||
$ aws s3 cp ./ s3://your-bucket-name --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --recursive |
||||
``` |
||||
Here is some explanations |
||||
> **./account** |
||||
> the path of folder which we want to upload |
||||
> |
||||
> **s3://woop-js-sdk-doc** |
||||
> the bucket name on AWS S3 |
||||
> |
||||
> **--grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers** |
||||
> Grant read access to all user |
||||
> |
||||
> **--recursive** |
||||
> Command is performed on all files or objects under the specified directory or prefix. |
||||
|
||||
4. Open the folder in S3 bucket and find `index.html`, get the |
||||
`Object URL`, then make it public! |
@ -1,88 +1,169 @@ |
||||
import {harmony} from './harmony'; |
||||
import fetch from 'jest-fetch-mock'; |
||||
import { woop, checkCalledMethod } from './woop'; |
||||
|
||||
import demoAccounts from '../fixtures/testAccount.json'; |
||||
import { RPCMethod } from '@woop-js/network'; |
||||
|
||||
const bc = harmony.blockchain; |
||||
const bc = woop.blockchain; |
||||
|
||||
const testAccount = demoAccounts.Accounts[1]; |
||||
|
||||
describe('e2e test blockchain', () => { |
||||
beforeEach(() => { |
||||
fetch.resetMocks(); |
||||
}); |
||||
// net_*
|
||||
it('should test net_peerCount', async () => { |
||||
fetch.mockResponseOnce( |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "0x0"}), |
||||
); |
||||
const peerCount = await bc.net_peerCount(); |
||||
expect(harmony.utils.isHex(peerCount.result)).toEqual(true); |
||||
expect(checkCalledMethod(0, RPCMethod.PeerCount)).toEqual(true); |
||||
expect(woop.utils.isHex(peerCount.result)).toEqual(true); |
||||
}); |
||||
|
||||
it('should test net_version', async () => { |
||||
fetch.mockResponseOnce( |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "5"}), |
||||
); |
||||
const netVersion = await bc.net_version(); |
||||
const versionNumber = parseInt(netVersion.result as string, 10); |
||||
expect(netVersion.result).toEqual(`${versionNumber}`); |
||||
expect(checkCalledMethod(0, RPCMethod.NetVersion)).toEqual(true); |
||||
}); |
||||
it('should test hmy_protocolVersion', async () => { |
||||
it('should test wiki_protocolVersion', async () => { |
||||
fetch.mockResponseOnce( |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "0x10"}), |
||||
); |
||||
const protocolVersion = await bc.getProtocolVersion(); |
||||
expect(harmony.utils.isHex(protocolVersion.result)).toEqual(true); |
||||
expect(woop.utils.isHex(protocolVersion.result)).toEqual(true); |
||||
expect(checkCalledMethod(0, RPCMethod.ProtocolVersion)).toEqual(true); |
||||
}); |
||||
|
||||
// block chain info
|
||||
it('should test hmy_blockNumber', async () => { |
||||
it('should test wiki_blockNumber', async () => { |
||||
fetch.mockResponseOnce( |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "0x10"}), |
||||
); |
||||
const res = await bc.getBlockNumber(); |
||||
expect(res.responseType).toEqual('raw'); |
||||
expect(harmony.utils.isHex(res.result)).toEqual(true); |
||||
expect(woop.utils.isHex(res.result)).toEqual(true); |
||||
expect(checkCalledMethod(0, RPCMethod.BlockNumber)).toEqual(true); |
||||
}); |
||||
it('should test hmy_getBlockByNumber', async () => { |
||||
const res = await bc.getBlockByNumber({blockNumber: 'latest'}); |
||||
|
||||
it('should test wiki_getBlockByNumber', async () => { |
||||
fetch.mockResponse( |
||||
JSON.stringify({ |
||||
"jsonrpc": "2.0", |
||||
"id": 1, |
||||
"result": { |
||||
"size": "0x1", |
||||
"difficulty": 5, |
||||
"extraData": "0x", |
||||
"gasLimit": "0x80", |
||||
"gasUsed": "0x40", |
||||
"hash": "0x8a3390ab500Fbca6514eB326d2fcD9B3BFCFbA7DA392593cB4885b8e3399a2D8", |
||||
"logsBloom": "0x0", |
||||
"miner": "one155jp2y76nazx8uw5sa94fr0m4s5aj8e5xm6fu3", |
||||
"mixHash": "0x3A7c1Ae14AfecFf55Da298F66b75F4FfB771c3EaBDeAa267FF33A77d4d0be220", |
||||
"nonce": 1, |
||||
"number": "0x1", |
||||
"parentHash": "0x7CebC07e456F0bCD09dbc9A6f271074d93E27B40A4C67Dcc402e6513e12B9aF9", |
||||
"receiptsRoot": "0x02B82e11eDC07775Dc6fCF706be2cdAF9165750Ea7bC1B3Eb48ea16Bb3072F4D", |
||||
"stateRoot": "0xAaDc89C8bA4e3fCfC140cFcc8D3efD3BE7a49ab31534A5a3F0E1DEA09aae0f4a", |
||||
"timestamp": "0x62c44c0a", |
||||
"transactionsRoot": "0xc4bfa888fDCC8ca70E2b0CcdCEcc2fF545acCC2D655Ba33DaF4aBc31cFDBd9Ac", |
||||
"uncles": [] |
||||
} |
||||
}), |
||||
); |
||||
const res = await bc.getBlockByNumber({ blockNumber: 'latest' }); |
||||
const size = res.result.size; |
||||
expect(res.responseType).toEqual('raw'); |
||||
expect(harmony.utils.isHex(size)).toEqual(true); |
||||
expect(woop.utils.isHex(size)).toEqual(true); |
||||
expect(checkBlockData(res.result)).toEqual(true); |
||||
const res2 = await bc.getBlockByNumber({blockNumber: res.result.number}); |
||||
const res2 = await bc.getBlockByNumber({ blockNumber: res.result.number }); |
||||
expect(res2.responseType).toEqual('raw'); |
||||
expect(harmony.utils.isHex(res2.result.size)).toEqual(true); |
||||
expect(woop.utils.isHex(res2.result.size)).toEqual(true); |
||||
expect(checkBlockData(res2.result)).toEqual(true); |
||||
const res3 = await bc.getBlockByNumber({returnObject: true}); |
||||
const res3 = await bc.getBlockByNumber({ returnObject: true }); |
||||
expect(res3.responseType).toEqual('raw'); |
||||
expect(checkBlockData(res3.result)).toEqual(true); |
||||
for(let i = 0; i < 3; i++) { |
||||
expect(checkCalledMethod(i, RPCMethod.GetBlockByNumber)).toEqual(true); |
||||
} |
||||
}); |
||||
|
||||
it('should test hmy_getBlockByHash', async () => { |
||||
const latestBlock = await bc.getBlockByNumber({blockNumber: 'latest'}); |
||||
const res = await bc.getBlockByHash({blockHash: latestBlock.result.hash}); |
||||
it('should test wiki_getBlockByHash', async () => { |
||||
fetch.mockResponse( |
||||
JSON.stringify({ |
||||
"jsonrpc": "2.0", |
||||
"id": 1, |
||||
"result": { |
||||
"size": "0x1", |
||||
"difficulty": 5, |
||||
"extraData": "0x", |
||||
"gasLimit": "0x80", |
||||
"gasUsed": "0x40", |
||||
"hash": "0x8a3390ab500Fbca6514eB326d2fcD9B3BFCFbA7DA392593cB4885b8e3399a2D8", |
||||
"logsBloom": "0x0", |
||||
"miner": "one155jp2y76nazx8uw5sa94fr0m4s5aj8e5xm6fu3", |
||||
"mixHash": "0x3A7c1Ae14AfecFf55Da298F66b75F4FfB771c3EaBDeAa267FF33A77d4d0be220", |
||||
"nonce": 1, |
||||
"number": "0x1", |
||||
"parentHash": "0x7CebC07e456F0bCD09dbc9A6f271074d93E27B40A4C67Dcc402e6513e12B9aF9", |
||||
"receiptsRoot": "0x02B82e11eDC07775Dc6fCF706be2cdAF9165750Ea7bC1B3Eb48ea16Bb3072F4D", |
||||
"stateRoot": "0xAaDc89C8bA4e3fCfC140cFcc8D3efD3BE7a49ab31534A5a3F0E1DEA09aae0f4a", |
||||
"timestamp": "0x62c44c0a", |
||||
"transactionsRoot": "0xc4bfa888fDCC8ca70E2b0CcdCEcc2fF545acCC2D655Ba33DaF4aBc31cFDBd9Ac", |
||||
"uncles": [] |
||||
} |
||||
}), |
||||
); |
||||
const latestBlock = await bc.getBlockByNumber({ blockNumber: 'latest' }); |
||||
const res = await bc.getBlockByHash({ blockHash: latestBlock.result.hash }); |
||||
expect(res.responseType).toEqual('raw'); |
||||
expect(latestBlock.result.hash).toEqual(res.result.hash); |
||||
expect(harmony.utils.isHex(res.result.size)).toEqual(true); |
||||
expect(woop.utils.isHex(res.result.size)).toEqual(true); |
||||
expect(checkBlockData(res.result)).toEqual(true); |
||||
expect(checkCalledMethod(0, RPCMethod.GetBlockByNumber)).toEqual(true); |
||||
expect(checkCalledMethod(1, RPCMethod.GetBlockByHash)).toEqual(true); |
||||
}); |
||||
|
||||
// account related
|
||||
it('should test hmy_getBalance', async () => { |
||||
const balance = await bc.getBalance({address: testAccount.Address}); |
||||
expect(harmony.utils.isHex(balance.result)).toEqual(true); |
||||
it('should test wiki_getBalance', async () => { |
||||
fetch.mockResponseOnce( |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "0x10"}), |
||||
); |
||||
const balance = await bc.getBalance({ address: testAccount.Address }); |
||||
expect(woop.utils.isHex(balance.result)).toEqual(true); |
||||
expect(checkCalledMethod(0, RPCMethod.GetBalance)).toEqual(true); |
||||
}); |
||||
}); |
||||
|
||||
function checkBlockData(data: any) { |
||||
return harmony.utils.validateArgs( |
||||
return woop.utils.validateArgs( |
||||
data, |
||||
{ |
||||
difficulty: [harmony.utils.isNumber], |
||||
difficulty: [woop.utils.isNumber], |
||||
// tslint:disable-next-line: no-shadowed-variable
|
||||
extraData: [(data: any) => data === '0x' || harmony.utils.isHex(data)], |
||||
gasLimit: [harmony.utils.isHex], |
||||
gasUsed: [harmony.utils.isHex], |
||||
hash: [harmony.utils.isHash], |
||||
logsBloom: [harmony.utils.isHex], |
||||
miner: [harmony.utils.isAddress], |
||||
mixHash: [harmony.utils.isHash], |
||||
nonce: [harmony.utils.isNumber], |
||||
number: [harmony.utils.isHex], |
||||
parentHash: [harmony.utils.isHash], |
||||
receiptsRoot: [harmony.utils.isHash], |
||||
size: [harmony.utils.isHex], |
||||
stateRoot: [harmony.utils.isHash], |
||||
timestamp: [harmony.utils.isHex], |
||||
transactionsRoot: [harmony.utils.isHash], |
||||
uncles: [harmony.utils.isArray], |
||||
extraData: [(data: any) => data === '0x' || woop.utils.isHex(data)], |
||||
gasLimit: [woop.utils.isHex], |
||||
gasUsed: [woop.utils.isHex], |
||||
hash: [woop.utils.isHash], |
||||
logsBloom: [woop.utils.isHex], |
||||
miner: [woop.utils.isBech32Address], |
||||
mixHash: [woop.utils.isHash], |
||||
nonce: [woop.utils.isNumber], |
||||
number: [woop.utils.isHex], |
||||
parentHash: [woop.utils.isHash], |
||||
receiptsRoot: [woop.utils.isHash], |
||||
size: [woop.utils.isHex], |
||||
stateRoot: [woop.utils.isHash], |
||||
timestamp: [woop.utils.isHex], |
||||
transactionsRoot: [woop.utils.isHash], |
||||
uncles: [woop.utils.isArray], |
||||
}, |
||||
{transactions: [harmony.utils.isArray]}, |
||||
{ transactions: [woop.utils.isArray] }, |
||||
); |
||||
} |
||||
} |
@ -1,29 +0,0 @@ |
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { Harmony } from '@harmony-js/core'; |
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { ChainType } from '@harmony-js/utils'; |
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { Account } from '@harmony-js/account'; |
||||
|
||||
const CHAIN_ID: number = parseInt(process.env.CHAIN_ID as string, 10); |
||||
const CHAIN_TYPE: string = process.env.CHAIN_TYPE as string; |
||||
const HTTP_PROVIDER: string = process.env.HTTP_PROVIDER as string; |
||||
const GENESIS_PRIV_KEY: string = process.env.GENESIS_PRIV_KEY as string; |
||||
|
||||
let chainType: ChainType = ChainType.Harmony; |
||||
|
||||
if (CHAIN_TYPE === 'hmy') { |
||||
chainType = ChainType.Harmony; |
||||
} else if (CHAIN_TYPE === 'eth') { |
||||
chainType = ChainType.Ethereum; |
||||
} |
||||
|
||||
export const harmony: Harmony = new Harmony(HTTP_PROVIDER, { |
||||
chainId: CHAIN_ID, |
||||
chainType, |
||||
chainUrl: HTTP_PROVIDER, |
||||
}); |
||||
|
||||
export const myAccount: Account = harmony.wallet.addByPrivateKey( |
||||
GENESIS_PRIV_KEY, |
||||
); |
@ -0,0 +1,39 @@ |
||||
import fetch from 'jest-fetch-mock'; |
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { Woop } from '@woop-js/core'; |
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { ChainType } from '@woop-js/utils'; |
||||
// tslint:disable-next-line: no-implicit-dependencies
|
||||
import { Account } from '@woop-js/account'; |
||||
|
||||
const CHAIN_ID: number = 2; |
||||
const CHAIN_TYPE: string = 'wiki'; |
||||
const HTTP_PROVIDER: string = 'http://localhost:9500'; |
||||
const GENESIS_PRIV_KEY: string = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'; |
||||
|
||||
let chainType: ChainType = ChainType.Woop; |
||||
|
||||
if (CHAIN_TYPE === 'wiki') { |
||||
chainType = ChainType.Woop; |
||||
} else if (CHAIN_TYPE === 'eth') { |
||||
chainType = ChainType.Ethereum; |
||||
} |
||||
|
||||
export const woop: Woop = new Woop(HTTP_PROVIDER, { |
||||
chainId: CHAIN_ID, |
||||
chainType, |
||||
chainUrl: HTTP_PROVIDER, |
||||
}); |
||||
|
||||
export const myAccount: Account = woop.wallet.addByPrivateKey( |
||||
GENESIS_PRIV_KEY, |
||||
); |
||||
|
||||
export function checkCalledMethod(i: number, s: string) { |
||||
let params: (string | undefined) = fetch.mock.calls[i][1]?.body?.toString(); |
||||
if (params) { |
||||
let method: string = JSON.parse(params).method; |
||||
return method === s; |
||||
} |
||||
return false; |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@ |
||||
# Packages available are: |
||||
|
||||
1. [@woop-js/core](https://github.com/woop-chain/sdk/tree/master/packages/woop-core) |
||||
2. [@woop-js/account](https://github.com/woop-chain/sdk/tree/master/packages/woop-account) |
||||
3. [@woop-js/crypto](https://github.com/woop-chain/sdk/tree/master/packages/woop-crypto) |
||||
4. [@woop-js/network](https://github.com/woop-chain/sdk/tree/master/packages/woop-network) |
||||
5. [@woop-js/utils](https://github.com/woop-chain/sdk/tree/master/packages/woop-utils) |
||||
6. [@woop-js/transaction](https://github.com/woop-chain/sdk/tree/master/packages/woop-transaction) |
||||
7. [@woop-js/contract](https://github.com/woop-chain/sdk/tree/master/packages/woop-contract) |
||||
8. [@woop-js/staking](https://github.com/woop-chain/sdk/tree/master/packages/woop-staking) |
||||
|
||||
<mark>Package level documentation and examples are inside each package</mark> |
@ -1,9 +0,0 @@ |
||||
# Usage |
||||
|
||||
```typescript |
||||
|
||||
import {Wallet} from '@harmony-js/account' |
||||
|
||||
const wallet=new Wallet() |
||||
|
||||
``` |
@ -1,8 +0,0 @@ |
||||
import { HttpProvider, Messenger } from '@harmony-js/network'; |
||||
import { ChainType, ChainID } from '@harmony-js/utils'; |
||||
|
||||
export const defaultMessenger = new Messenger( |
||||
new HttpProvider('http://localhost:9500'), |
||||
ChainType.Harmony, |
||||
ChainID.HmyLocal, |
||||
); |
@ -1,15 +0,0 @@ |
||||
{ |
||||
"extends": "../../tsconfig.base.json", |
||||
"compilerOptions": { |
||||
"rootDir": "src", |
||||
"outDir": "dist" |
||||
}, |
||||
"include": ["src", "../../typings/**/*.d.ts"], |
||||
"references": [ |
||||
{ "path": "../harmony-crypto" }, |
||||
{ "path": "../harmony-utils" }, |
||||
{ "path": "../harmony-transaction" }, |
||||
{ "path": "../harmony-staking" }, |
||||
{ "path": "../harmony-network" } |
||||
] |
||||
} |
@ -1,10 +0,0 @@ |
||||
export * from './abi/index'; |
||||
export { |
||||
toUtf8Bytes, |
||||
toUtf8String, |
||||
formatBytes32String, |
||||
parseBytes32String, |
||||
} from './abi/abiCoder'; |
||||
|
||||
export { Contract } from './contract'; |
||||
export { ContractFactory } from './contractFactory'; |
File diff suppressed because one or more lines are too long
@ -1,30 +0,0 @@ |
||||
{ |
||||
"name": "@harmony-js/core", |
||||
"version": "0.1.32", |
||||
"description": "harmony core package", |
||||
"main": "dist/index.js", |
||||
"node": "dist/index.js", |
||||
"browser": "dist/index.js", |
||||
"module": "dist/index.esm.js", |
||||
"jsnext:main": "dist/index.esm.js", |
||||
"typings": "dist/index.d.ts", |
||||
"types": "dist/index.d.ts", |
||||
"scripts": { |
||||
"test": "echo \"Error: no test specified\" && exit 1" |
||||
}, |
||||
"publishConfig": { |
||||
"access": "public" |
||||
}, |
||||
"author": "neeboo@firestack.one", |
||||
"license": "MIT", |
||||
"dependencies": { |
||||
"@harmony-js/account": "0.1.32", |
||||
"@harmony-js/contract": "0.1.32", |
||||
"@harmony-js/crypto": "0.1.32", |
||||
"@harmony-js/network": "0.1.31", |
||||
"@harmony-js/staking": "0.1.32", |
||||
"@harmony-js/transaction": "0.1.32", |
||||
"@harmony-js/utils": "0.1.28" |
||||
}, |
||||
"gitHead": "0f2c4f00383611397ba83182322be3394451f8d6" |
||||
} |
@ -1,526 +0,0 @@ |
||||
import { |
||||
RPCMethod, |
||||
Messenger, |
||||
ResponseMiddleware, |
||||
WSProvider, |
||||
NewPendingTransactions, |
||||
NewHeaders, |
||||
LogSub, |
||||
Syncing, |
||||
} from '@harmony-js/network'; |
||||
|
||||
import { |
||||
assertObject, |
||||
AssertType, |
||||
// HarmonyCore,
|
||||
DefaultBlockParams, |
||||
} from '@harmony-js/utils'; |
||||
|
||||
import { getAddress } from '@harmony-js/crypto'; |
||||
|
||||
import { Transaction } from '@harmony-js/transaction'; |
||||
import { StakingTransaction } from '@harmony-js/staking'; |
||||
|
||||
class Blockchain { |
||||
messenger: Messenger; |
||||
|
||||
constructor(messenger: Messenger) { |
||||
this.messenger = messenger; |
||||
} |
||||
setMessenger(messenger: Messenger) { |
||||
this.messenger = messenger; |
||||
} |
||||
getRpcResult(result: any) { |
||||
if (result instanceof ResponseMiddleware) { |
||||
return result.getRaw; |
||||
} else { |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
@assertObject({ |
||||
address: ['isValidAddress', AssertType.required], |
||||
blockNumber: ['isBlockNumber', AssertType.optional], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getBalance({ |
||||
address, |
||||
blockNumber = DefaultBlockParams.latest, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
address: string; |
||||
blockNumber?: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetBalance, |
||||
[getAddress(address).checksum, blockNumber], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
async getBlockNumber(shardID: number = this.messenger.currentShard) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.BlockNumber, |
||||
[], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
/** |
||||
* |
||||
*/ |
||||
@assertObject({ |
||||
blockHash: ['isHash', AssertType.required], |
||||
returnObject: ['isBoolean', AssertType.optional], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getBlockByHash({ |
||||
blockHash, |
||||
returnObject = true, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
blockHash: string; |
||||
returnObject?: boolean; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetBlockByHash, |
||||
[blockHash, returnObject], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
@assertObject({ |
||||
blockNumber: ['isBlockNumber', AssertType.optional], |
||||
returnObject: ['isBoolean', AssertType.optional], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getBlockByNumber({ |
||||
blockNumber = DefaultBlockParams.latest, |
||||
returnObject = true, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
blockNumber?: string; |
||||
returnObject?: boolean; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetBlockByNumber, |
||||
[blockNumber, returnObject], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
@assertObject({ |
||||
blockHash: ['isHash', AssertType.required], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getBlockTransactionCountByHash({ |
||||
blockHash, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
blockHash: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetBlockTransactionCountByHash, |
||||
[blockHash], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
@assertObject({ |
||||
blockNumber: ['isBlockNumber', AssertType.required], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getBlockTransactionCountByNumber({ |
||||
blockNumber, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
blockNumber: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetBlockTransactionCountByNumber, |
||||
[blockNumber], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
@assertObject({ |
||||
blockHash: ['isHash', AssertType.required], |
||||
index: ['isHex', AssertType.required], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getTransactionByBlockHashAndIndex({ |
||||
blockHash, |
||||
index, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
blockHash: string; |
||||
index: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetTransactionByBlockHashAndIndex, |
||||
[blockHash, index], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
@assertObject({ |
||||
blockNumber: ['isBlockNumber', AssertType.optional], |
||||
index: ['isHex', AssertType.required], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getTransactionByBlockNumberAndIndex({ |
||||
blockNumber = DefaultBlockParams.latest, |
||||
index, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
blockNumber?: string; |
||||
index: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetTransactionByBlockNumberAndIndex, |
||||
[blockNumber, index], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
@assertObject({ |
||||
txnHash: ['isHash', AssertType.required], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getTransactionByHash({ |
||||
txnHash, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
txnHash: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetTransactionByHash, |
||||
[txnHash], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
@assertObject({ |
||||
txnHash: ['isString', AssertType.required], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getTransactionReceipt({ |
||||
txnHash, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
txnHash: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetTransactionReceipt, |
||||
[txnHash], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
@assertObject({ |
||||
txnHash: ['isString', AssertType.required], |
||||
shardID: ['isNumber', AssertType.required], |
||||
}) |
||||
async getCxReceiptByHash({ txnHash, shardID }: { txnHash: string; shardID: number }) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetCXReceiptByHash, |
||||
[txnHash], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
/** |
||||
* |
||||
*/ |
||||
@assertObject({ |
||||
address: ['isValidAddress', AssertType.required], |
||||
blockNumber: ['isBlockNumber', AssertType.optional], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getCode({ |
||||
address, |
||||
blockNumber = DefaultBlockParams.latest, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
address: string; |
||||
blockNumber?: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetCode, |
||||
[getAddress(address).checksum, blockNumber], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
async net_peerCount(shardID: number = this.messenger.currentShard) { |
||||
const result = await this.messenger.send(RPCMethod.PeerCount, [], 'net', shardID); |
||||
|
||||
return this.getRpcResult(result); |
||||
} |
||||
async net_version(shardID: number = this.messenger.currentShard) { |
||||
const result = await this.messenger.send(RPCMethod.NetVersion, [], 'net', shardID); |
||||
|
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
async getProtocolVersion(shardID: number = this.messenger.currentShard) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.ProtocolVersion, |
||||
[], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
@assertObject({ |
||||
address: ['isValidAddress', AssertType.required], |
||||
position: ['isHex', AssertType.required], |
||||
blockNumber: ['isBlockNumber', AssertType.optional], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getStorageAt({ |
||||
address, |
||||
position, |
||||
blockNumber = DefaultBlockParams.latest, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
address: string; |
||||
position: string; |
||||
blockNumber?: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetStorageAt, |
||||
[getAddress(address).checksum, position, blockNumber], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
@assertObject({ |
||||
address: ['isValidAddress', AssertType.required], |
||||
blockNumber: ['isBlockNumber', AssertType.optional], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async getTransactionCount({ |
||||
address, |
||||
blockNumber = DefaultBlockParams.latest, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
address: string; |
||||
blockNumber?: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetTransactionCount, |
||||
[getAddress(address).checksum, blockNumber], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
async getShardingStructure() { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GetShardingStructure, |
||||
[], |
||||
this.messenger.chainPrefix, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
async sendTransaction(transaction: Transaction) { |
||||
if (!transaction.isSigned() || !transaction) { |
||||
throw new Error('transaction is not signed or not exist'); |
||||
} |
||||
const result = await this.messenger.send( |
||||
RPCMethod.SendRawTransaction, |
||||
[transaction.getRawTransaction()], |
||||
this.messenger.chainPrefix, |
||||
typeof transaction.txParams.shardID === 'string' |
||||
? Number.parseInt(transaction.txParams.shardID, 10) |
||||
: transaction.txParams.shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
async sendRawTransaction(transaction: Transaction) { |
||||
if (!transaction.isSigned() || !transaction) { |
||||
throw new Error('transaction is not signed or not exist'); |
||||
} |
||||
const [txn, result] = await transaction.sendTransaction(); |
||||
if (txn.isPending()) { |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
createObservedTransaction(transaction: Transaction) { |
||||
try { |
||||
transaction.sendTransaction().then((response: any) => { |
||||
const [txReturned, TranID] = response; |
||||
|
||||
txReturned.confirm(TranID).then((txConfirmed: Transaction) => { |
||||
transaction.emitter.resolve(txConfirmed); |
||||
}); |
||||
}); |
||||
return transaction.emitter; |
||||
} catch (err) { |
||||
throw err; |
||||
} |
||||
} |
||||
|
||||
async sendRawStakingTransaction(staking: StakingTransaction) { |
||||
if (!staking.isSigned() || !staking) { |
||||
throw new Error('staking transaction is not signed or not exist'); |
||||
} |
||||
const [txn, result] = await staking.sendTransaction(); |
||||
if (txn.isPending()) { |
||||
return result; |
||||
} |
||||
} |
||||
createObservedStakingTransaction(staking: StakingTransaction) { |
||||
try { |
||||
staking.sendTransaction().then((response: any) => { |
||||
const [txReturned, TranID] = response; |
||||
|
||||
txReturned.confirm(TranID).then((txConfirmed: StakingTransaction) => { |
||||
staking.emitter.resolve(txConfirmed); |
||||
}); |
||||
}); |
||||
return staking.emitter; |
||||
} catch (err) { |
||||
throw err; |
||||
} |
||||
} |
||||
|
||||
@assertObject({ |
||||
to: ['isValidAddress', AssertType.optional], |
||||
data: ['isHex', AssertType.optional], |
||||
shardID: ['isNumber', AssertType.optional], |
||||
}) |
||||
async estimateGas({ |
||||
to, |
||||
data, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
to: string; |
||||
data: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.EstimateGas, |
||||
[{ to: getAddress(to).checksum, data }], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
async gasPrice(shardID: number = this.messenger.currentShard) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.GasPrice, |
||||
[], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
async call({ |
||||
payload, |
||||
blockNumber = DefaultBlockParams.latest, |
||||
shardID = this.messenger.currentShard, |
||||
}: { |
||||
payload: any; |
||||
blockNumber?: string; |
||||
shardID?: number; |
||||
}) { |
||||
const result = await this.messenger.send( |
||||
RPCMethod.Call, |
||||
[payload, blockNumber], |
||||
this.messenger.chainPrefix, |
||||
shardID, |
||||
); |
||||
return this.getRpcResult(result); |
||||
} |
||||
|
||||
newPendingTransactions(shardID: number = this.messenger.currentShard) { |
||||
if (this.messenger.provider instanceof WSProvider) { |
||||
return new NewPendingTransactions(this.messenger, shardID); |
||||
} else { |
||||
throw new Error('HttpProvider does not support this feature'); |
||||
} |
||||
} |
||||
|
||||
newBlockHeaders(shardID: number = this.messenger.currentShard) { |
||||
if (this.messenger.provider instanceof WSProvider) { |
||||
return new NewHeaders(this.messenger, shardID); |
||||
} else { |
||||
throw new Error('HttpProvider does not support this feature'); |
||||
} |
||||
} |
||||
|
||||
syncing(shardID: number = this.messenger.currentShard) { |
||||
if (this.messenger.provider instanceof WSProvider) { |
||||
return new Syncing(this.messenger, shardID); |
||||
} else { |
||||
throw new Error('HttpProvider does not support this feature'); |
||||
} |
||||
} |
||||
|
||||
logs(options: any, shardID: number = this.messenger.currentShard) { |
||||
if (this.messenger.provider instanceof WSProvider) { |
||||
return new LogSub(options, this.messenger, shardID); |
||||
} else { |
||||
throw new Error('HttpProvider does not support this feature'); |
||||
} |
||||
} |
||||
} |
||||
|
||||
export { Blockchain }; |
@ -1,99 +0,0 @@ |
||||
import * as crypto from '@harmony-js/crypto'; |
||||
import * as utils from '@harmony-js/utils'; |
||||
|
||||
import { Provider, HttpProvider, Messenger, WSProvider, ShardingItem } from '@harmony-js/network'; |
||||
import { TransactionFactory, Transaction } from '@harmony-js/transaction'; |
||||
import { StakingTransaction } from '@harmony-js/staking'; |
||||
import { ContractFactory, Contract } from '@harmony-js/contract'; |
||||
import { Wallet, Account } from '@harmony-js/account'; |
||||
import { Blockchain } from './blockchain'; |
||||
import { HarmonyConfig } from './util'; |
||||
|
||||
export class Harmony extends utils.HarmonyCore { |
||||
Modules = { |
||||
HttpProvider, |
||||
WSProvider, |
||||
Messenger, |
||||
Blockchain, |
||||
TransactionFactory, |
||||
Wallet, |
||||
Transaction, |
||||
StakingTransaction, |
||||
Account, |
||||
Contract, |
||||
}; |
||||
messenger: Messenger; |
||||
transactions: TransactionFactory; |
||||
wallet: Wallet; |
||||
blockchain: Blockchain; |
||||
contracts: ContractFactory; |
||||
crypto: any; |
||||
utils: any; |
||||
defaultShardID?: number; |
||||
private provider: HttpProvider | WSProvider; |
||||
|
||||
constructor( |
||||
url: string, |
||||
config: HarmonyConfig = { |
||||
chainId: utils.defaultConfig.Default.Chain_ID, |
||||
chainType: utils.defaultConfig.Default.Chain_Type, |
||||
}, |
||||
) { |
||||
super(config.chainType, config.chainId); |
||||
|
||||
const providerUrl = config.chainUrl || url || utils.defaultConfig.Default.Chain_URL; |
||||
|
||||
this.provider = new Provider(providerUrl).provider; |
||||
this.messenger = new Messenger(this.provider, this.chainType, this.chainId); |
||||
this.blockchain = new Blockchain(this.messenger); |
||||
this.transactions = new TransactionFactory(this.messenger); |
||||
this.wallet = new Wallet(this.messenger); |
||||
this.contracts = new ContractFactory(this.wallet); |
||||
this.crypto = crypto; |
||||
this.utils = utils; |
||||
this.defaultShardID = config.shardID; |
||||
if (this.defaultShardID !== undefined) { |
||||
this.setShardID(this.defaultShardID); |
||||
} |
||||
} |
||||
public setProvider(provider: string | HttpProvider | WSProvider): void { |
||||
this.provider = new Provider(provider).provider; |
||||
this.messenger.setProvider(this.provider); |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
|
||||
public setChainId(chainId: utils.ChainID) { |
||||
this.chainId = chainId; |
||||
this.messenger.setChainId(this.chainId); |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
public setShardID(shardID: number) { |
||||
this.defaultShardID = shardID; |
||||
this.messenger.setDefaultShardID(this.defaultShardID); |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
public setChainType(chainType: utils.ChainType) { |
||||
this.chainType = chainType; |
||||
this.messenger.setChainType(this.chainType); |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
|
||||
public shardingStructures(shardingStructures: ShardingItem[]) { |
||||
for (const shard of shardingStructures) { |
||||
const shardID = |
||||
typeof shard.shardID === 'string' ? Number.parseInt(shard.shardID, 10) : shard.shardID; |
||||
this.messenger.shardProviders.set(shardID, { |
||||
current: shard.current !== undefined ? shard.current : false, |
||||
shardID, |
||||
http: shard.http, |
||||
ws: shard.ws, |
||||
}); |
||||
} |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
private setMessenger(messenger: Messenger) { |
||||
this.blockchain.setMessenger(messenger); |
||||
this.wallet.setMessenger(messenger); |
||||
this.transactions.setMessenger(messenger); |
||||
} |
||||
} |
@ -1,5 +0,0 @@ |
||||
export * from './harmony'; |
||||
export * from './blockchain'; |
||||
export * from './truffleProvider'; |
||||
export * from './harmonyExtension'; |
||||
export * from './types'; |
@ -1,25 +0,0 @@ |
||||
import { HttpProvider, Messenger } from '@harmony-js/network'; |
||||
import { TransactionFactory, Transaction } from '@harmony-js/transaction'; |
||||
import { Wallet, Account } from '@harmony-js/account'; |
||||
import { ChainType, ChainID } from '@harmony-js/utils'; |
||||
import { Blockchain } from './blockchain'; |
||||
|
||||
export interface HarmonyModule { |
||||
HttpProvider: HttpProvider; |
||||
Messenger: Messenger; |
||||
Blockchain: Blockchain; |
||||
TransactionFactory: TransactionFactory; |
||||
Wallet: Wallet; |
||||
Transaction: Transaction; |
||||
Account: Account; |
||||
} |
||||
|
||||
export const enum UrlType { |
||||
http, |
||||
ws, |
||||
} |
||||
|
||||
export interface HarmonySetting<T extends ChainType, I extends ChainID> { |
||||
type: T; |
||||
id: I; |
||||
} |
@ -1,16 +0,0 @@ |
||||
{ |
||||
"extends": "../../tsconfig.base.json", |
||||
"compilerOptions": { |
||||
"rootDir": "src", |
||||
"outDir": "dist" |
||||
}, |
||||
"include": ["src", "../../typings/**/*.d.ts", "../harmony-utils/src/core.ts"], |
||||
"references": [ |
||||
{"path": "../harmony-account"}, |
||||
{"path": "../harmony-crypto"}, |
||||
{"path": "../harmony-utils"}, |
||||
{"path": "../harmony-network"}, |
||||
{"path": "../harmony-transaction"}, |
||||
{"path": "../harmony-contract"} |
||||
] |
||||
} |
@ -1,80 +0,0 @@ |
||||
import { isAddress, isBech32Address, isBech32TestNetAddress } from '@harmony-js/utils'; |
||||
|
||||
import { toChecksumAddress } from './keyTool'; |
||||
import { fromBech32, toBech32, HRP, tHRP } from './bech32'; |
||||
|
||||
export class HarmonyAddress { |
||||
// static validator
|
||||
static isValidBasic(str: string) { |
||||
const toTest = new HarmonyAddress(str); |
||||
return toTest.raw === toTest.basic; |
||||
} |
||||
|
||||
// static validator
|
||||
static isValidChecksum(str: string) { |
||||
const toTest = new HarmonyAddress(str); |
||||
return toTest.raw === toTest.checksum; |
||||
} |
||||
|
||||
// static validator
|
||||
static isValidBech32(str: string) { |
||||
const toTest = new HarmonyAddress(str); |
||||
return toTest.raw === toTest.bech32; |
||||
} |
||||
// static validator
|
||||
static isValidBech32TestNet(str: string) { |
||||
const toTest = new HarmonyAddress(str); |
||||
return toTest.raw === toTest.bech32TestNet; |
||||
} |
||||
|
||||
raw: string; |
||||
basic: string; |
||||
get basicHex() { |
||||
return `0x${this.basic}`; |
||||
} |
||||
get checksum() { |
||||
return toChecksumAddress(`0x${this.basic}`); |
||||
} |
||||
|
||||
get bech32() { |
||||
return toBech32(this.basic, HRP); |
||||
} |
||||
get bech32TestNet() { |
||||
return toBech32(this.basic, tHRP); |
||||
} |
||||
|
||||
constructor(raw: string) { |
||||
this.raw = raw; |
||||
this.basic = this.getBasic(this.raw); |
||||
} |
||||
|
||||
private getBasic(addr: string) { |
||||
const basicBool = isAddress(addr); |
||||
const bech32Bool = isBech32Address(addr); |
||||
const bech32TestNetBool = isBech32TestNetAddress(addr); |
||||
|
||||
if (basicBool) { |
||||
return addr.replace('0x', '').toLowerCase(); |
||||
} |
||||
|
||||
if (bech32Bool) { |
||||
const fromB32 = fromBech32(addr, HRP); |
||||
return fromB32.replace('0x', '').toLowerCase(); |
||||
} |
||||
|
||||
if (bech32TestNetBool) { |
||||
const fromB32TestNet = fromBech32(addr, tHRP); |
||||
return fromB32TestNet.replace('0x', '').toLowerCase(); |
||||
} |
||||
|
||||
throw new Error(`"${addr}" is an invalid address format`); |
||||
} |
||||
} |
||||
|
||||
export function getAddress(address: string) { |
||||
try { |
||||
return new HarmonyAddress(address); |
||||
} catch (error) { |
||||
throw error; |
||||
} |
||||
} |
@ -1,100 +0,0 @@ |
||||
export const enum RPCMethod { |
||||
// 1. hmy_getBlockByHash
|
||||
GetBlockByHash = 'hmy_getBlockByHash', |
||||
// 2. hmy_getBlockByNumber
|
||||
GetBlockByNumber = 'hmy_getBlockByNumber', |
||||
// 3. hmy_getBlockTransactionCountByHash
|
||||
GetBlockTransactionCountByHash = 'hmy_getBlockTransactionCountByHash', |
||||
// 4. hmy_getBlockTransactionCountByNumber
|
||||
GetBlockTransactionCountByNumber = 'hmy_getBlockTransactionCountByNumber', |
||||
// 5. hmy_getCode
|
||||
GetCode = 'hmy_getCode', |
||||
// 6. hmy_getTransactionByBlockHashAndIndex
|
||||
GetTransactionByBlockHashAndIndex = 'hmy_getTransactionByBlockHashAndIndex', |
||||
// 7. hmy_getTransactionByBlockNumberAndIndex
|
||||
GetTransactionByBlockNumberAndIndex = 'hmy_getTransactionByBlockNumberAndIndex', |
||||
// 8. hmy_getTransactionByHash
|
||||
GetTransactionByHash = 'hmy_getTransactionByHash', |
||||
|
||||
GetTransactionReceipt = 'hmy_getTransactionReceipt', |
||||
|
||||
GetCXReceiptByHash = 'hmy_getCXReceiptByHash', |
||||
// 9. hmy_syncing
|
||||
Syncing = 'hmy_syncing', |
||||
// 10. net_peerCount
|
||||
PeerCount = 'net_peerCount', |
||||
|
||||
// 11. hmy_getBalance
|
||||
GetBalance = 'hmy_getBalance', |
||||
// 12. hmy_getStorageAt
|
||||
GetStorageAt = 'hmy_getStorageAt', |
||||
// 13. hmy_getTransactionCount
|
||||
GetTransactionCount = 'hmy_getTransactionCount', |
||||
// 14. hmy_sendTransaction
|
||||
SendTransaction = 'hmy_sendTransaction', |
||||
// 15. hmy_sendRawTransaction
|
||||
SendRawTransaction = 'hmy_sendRawTransaction', |
||||
// 16. hmy_subscribe
|
||||
Subscribe = 'hmy_subscribe', |
||||
// 17. hmy_getlogs
|
||||
GetPastLogs = 'hmy_getLogs', |
||||
// 18. hmy_getWork
|
||||
GetWork = 'hmy_getWork', |
||||
// 19. hmy_submitWork
|
||||
// SubmitWork = 'hmy_submitWork',
|
||||
// 20. hmy_getProof
|
||||
GetProof = 'hmy_getProof', |
||||
// 21, hmy_getFilterChanges
|
||||
GetFilterChanges = 'hmy_getFilterChanges', |
||||
// 22. hmy_newPendingTransactionFilter
|
||||
NewPendingTransactionFilter = 'hmy_newPendingTransactionFilter', |
||||
// 23. hmy_newBlockFilter
|
||||
NewBlockFilter = 'hmy_newBlockFilter', |
||||
// 24. hmy_newFilter
|
||||
NewFilter = 'hmy_newFilter', |
||||
// 25. hmy_call
|
||||
Call = 'hmy_call', |
||||
// 26. hmy_estimateGas
|
||||
EstimateGas = 'hmy_estimateGas', |
||||
// 27. hmy_gasPrice
|
||||
GasPrice = 'hmy_gasPrice', |
||||
// 28. hmy_blockNumber
|
||||
BlockNumber = 'hmy_blockNumber', |
||||
// 29. hmy_unsubscribe
|
||||
UnSubscribe = 'hmy_unsubscribe', |
||||
// 30. net_version
|
||||
NetVersion = 'net_version', |
||||
// 31. hmy_protocolVersion
|
||||
ProtocolVersion = 'hmy_protocolVersion', |
||||
// 32. hmy_getShardingStructure
|
||||
GetShardingStructure = 'hmy_getShardingStructure', |
||||
// 33. hmy_sendRawStakingTransaction
|
||||
SendRawStakingTransaction = 'hmy_sendRawStakingTransaction', |
||||
} |
||||
|
||||
export const enum RPCErrorCode { |
||||
// Standard JSON-RPC 2.0 errors
|
||||
// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400).
|
||||
// It should not be used for application-layer errors.
|
||||
RPC_INVALID_REQUEST = -32600, |
||||
// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404).
|
||||
// It should not be used for application-layer errors.
|
||||
RPC_METHOD_NOT_FOUND = -32601, |
||||
RPC_INVALID_PARAMS = -32602, |
||||
// RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind
|
||||
// (for example datadir corruption).
|
||||
RPC_INTERNAL_ERROR = -32603, |
||||
RPC_PARSE_ERROR = -32700, |
||||
|
||||
// General application defined errors
|
||||
RPC_MISC_ERROR = -1, // std::exception thrown in command handling
|
||||
RPC_TYPE_ERROR = -3, // Unexpected type was passed as parameter
|
||||
RPC_INVALID_ADDRESS_OR_KEY = -5, // Invalid address or key
|
||||
RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter
|
||||
RPC_DATABASE_ERROR = -20, // Database error
|
||||
RPC_DESERIALIZATION_ERROR = -22, // Error parsing or validating structure in raw format
|
||||
RPC_VERIFY_ERROR = -25, // General error during transaction or block submission
|
||||
RPC_VERIFY_REJECTED = -26, // Transaction or block was rejected by network rules
|
||||
RPC_IN_WARMUP = -28, // Client still warming up
|
||||
RPC_METHOD_DEPRECATED = -32, // RPC method is deprecated
|
||||
} |
@ -1 +0,0 @@ |
||||
export * from './stakingTransaction'; |
@ -1,39 +0,0 @@ |
||||
import { getContractAddress, getAddress } from '@harmony-js/crypto'; |
||||
import { Messenger } from '@harmony-js/network'; |
||||
import { Transaction } from './transaction'; |
||||
import { ShardingTransaction } from './shardingTransaction'; |
||||
import { TxParams, TxStatus } from './types'; |
||||
|
||||
export class TransactionFactory { |
||||
static getContractAddress(tx: Transaction) { |
||||
const { from, nonce } = tx.txParams; |
||||
return getAddress( |
||||
getContractAddress(getAddress(from).checksum, Number.parseInt(`${nonce}`, 10)), |
||||
).checksum; |
||||
} |
||||
|
||||
messenger: Messenger; |
||||
constructor(messenger: Messenger) { |
||||
this.messenger = messenger; |
||||
} |
||||
setMessenger(messenger: Messenger) { |
||||
this.messenger = messenger; |
||||
} |
||||
|
||||
newTx(txParams?: TxParams | any, sharding: boolean = false): Transaction { |
||||
if (!sharding) { |
||||
return new Transaction(txParams, this.messenger, TxStatus.INTIALIZED); |
||||
} |
||||
return new ShardingTransaction(txParams, this.messenger, TxStatus.INTIALIZED); |
||||
} |
||||
|
||||
clone(transaction: Transaction): Transaction { |
||||
return new Transaction(transaction.txParams, this.messenger, TxStatus.INTIALIZED); |
||||
} |
||||
|
||||
recover(txHash: string): Transaction { |
||||
const newTxn = new Transaction({}, this.messenger, TxStatus.INTIALIZED); |
||||
newTxn.recover(txHash); |
||||
return newTxn; |
||||
} |
||||
} |
@ -1,48 +0,0 @@ |
||||
import { BN, Signature } from '@harmony-js/crypto'; |
||||
export interface TxParams { |
||||
id: string; |
||||
from: string; |
||||
to: string; |
||||
nonce: number | string; |
||||
gasLimit: number | string | BN; |
||||
gasPrice: number | string | BN; |
||||
shardID: number | string; |
||||
toShardID: number | string; |
||||
data: string; |
||||
value: number | string | BN; |
||||
chainId: number; |
||||
rawTransaction: string; |
||||
unsignedRawTransaction: string; |
||||
signature: Signature; |
||||
receipt?: TransasctionReceipt; |
||||
} |
||||
|
||||
export const enum TxStatus { |
||||
NONE = 'NONE', |
||||
INTIALIZED = 'INITIALIZED', |
||||
SIGNED = 'SIGNED', |
||||
PENDING = 'PENDING', |
||||
CONFIRMED = 'CONFIRMED', |
||||
REJECTED = 'REJECTED', |
||||
} |
||||
|
||||
export interface TransasctionReceipt { |
||||
transactionHash: string; |
||||
transactionIndex: string; |
||||
blockHash: string; |
||||
blockNumber: string; // 11
|
||||
from: string; |
||||
to: string; |
||||
gasUsed: string; |
||||
cumulativeGasUsed: string; // 13244
|
||||
contractAddress?: string | null; // or null, if none was created
|
||||
logs: any[]; |
||||
logsBloom: string; // 256 byte bloom filter
|
||||
v: string; |
||||
r: string; |
||||
s: string; |
||||
responseType?: string; |
||||
byzantium?: boolean; |
||||
status?: string; // post Byzantium will return `0x0` or `0x1`
|
||||
root?: string; // pre Byzantium will return `root`
|
||||
} |
@ -1,73 +0,0 @@ |
||||
export const enum ChainType { |
||||
Harmony = 'hmy', |
||||
Ethereum = 'eth', |
||||
} |
||||
|
||||
export const enum ChainID { |
||||
Default = 0, |
||||
EthMainnet = 1, |
||||
Morden = 2, |
||||
Ropsten = 3, |
||||
Rinkeby = 4, |
||||
RootstockMainnet = 30, |
||||
RootstockTestnet = 31, |
||||
Kovan = 42, |
||||
EtcMainnet = 61, |
||||
EtcTestnet = 62, |
||||
Geth = 1337, |
||||
Ganache = 0, |
||||
HmyMainnet = 1, |
||||
HmyTestnet = 2, |
||||
HmyLocal = 2, |
||||
HmyPangaea = 3, |
||||
} |
||||
|
||||
export const defaultConfig = { |
||||
Default: { |
||||
Chain_ID: ChainID.HmyLocal, |
||||
Chain_Type: ChainType.Harmony, |
||||
Chain_URL: 'http://localhost:9500', |
||||
Network_ID: 'Local', |
||||
}, |
||||
DefaultWS: { |
||||
Chain_ID: ChainID.HmyLocal, |
||||
Chain_Type: ChainType.Harmony, |
||||
Chain_URL: 'ws://localhost:9800', |
||||
Network_ID: 'LocalWS', |
||||
}, |
||||
}; |
||||
|
||||
export abstract class HarmonyCore { |
||||
chainType: ChainType; |
||||
chainId: ChainID; |
||||
constructor(chainType: ChainType, chainId: ChainID = defaultConfig.Default.Chain_ID) { |
||||
this.chainType = chainType; |
||||
this.chainId = chainId; |
||||
} |
||||
get chainPrefix(): string { |
||||
switch (this.chainType) { |
||||
case ChainType.Ethereum: { |
||||
return 'eth'; |
||||
} |
||||
case ChainType.Harmony: { |
||||
return 'hmy'; |
||||
} |
||||
default: { |
||||
return 'hmy'; |
||||
} |
||||
} |
||||
} |
||||
get getChainId(): ChainID { |
||||
return this.chainId; |
||||
} |
||||
public setChainId(chainId: ChainID) { |
||||
this.chainId = chainId; |
||||
} |
||||
public setChainType(chainType: ChainType) { |
||||
this.chainType = chainType; |
||||
} |
||||
} |
||||
|
||||
export const HDPath = `m/44'/1023'/0'/0/`; |
||||
|
||||
export const AddressSuffix = '-'; |
@ -0,0 +1,210 @@ |
||||
# @woop-js/account |
||||
|
||||
This package provides a collection of apis to create accounts and wallets and sign using them. A wallet can hold multiple accounts and account is associated with a unique `one` address. This package also provides facilies to manage account keys. |
||||
|
||||
## Installation |
||||
|
||||
``` |
||||
npm install @woop-js/account |
||||
``` |
||||
|
||||
## Usage |
||||
|
||||
Creating new account and display hex and bech32 (one) addresses |
||||
```javascript |
||||
const account = new Account(); // or const account = Account.new() |
||||
console.log(account.checksumAddress); |
||||
console.log(account.bech32Address); |
||||
``` |
||||
|
||||
Creating new account using private key |
||||
```javascript |
||||
const account = Account.add('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'); |
||||
``` |
||||
|
||||
Creating account using private key and custom messenger |
||||
```javascript |
||||
const account = new Account( |
||||
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e', |
||||
new Messenger( |
||||
new HttpProvider('https://api.s0.b.hmny.io'), |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
), |
||||
); |
||||
``` |
||||
|
||||
Creating account and setting custom messenger |
||||
```javascript |
||||
// uses by default http://localhost:9500 as messenger |
||||
const account = new Account(); |
||||
const customMessenger = new Messenger( |
||||
new HttpProvider('https://api.s0.b.hmny.io'), |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
); |
||||
|
||||
account.setMessenger(customMessenger); |
||||
``` |
||||
|
||||
Storing the account data to keystore file |
||||
```javascript |
||||
const passphrase = ''; |
||||
const account = new Account('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'); |
||||
account.toFile(passphrase).then(keystore => { |
||||
console.log(keystore); |
||||
}); |
||||
``` |
||||
|
||||
Fetching account from keystore file |
||||
```javascript |
||||
const passphrase = ''; |
||||
const keystore = '{"version":3,"id":"33363566-3564-4264-a638-363531666335","address":"7c41e0668b551f4f902cfaec05b5bdca68b124ce","crypto":{"ciphertext":"9b09380afb742838b32d9afc0ec1a3df35dbd7a41e3a160d08c07a4d0e79b855","cipherparams":{"iv":"1cd0e0522260eef055b9170f4825f4a0"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"salt":"bf35e36c45cccefcef73a4c900f41c682c94c28630d94d2d1f764760d245f30b","n":8192,"r":8,"p":1,"dklen":32},"mac":"25b4442972356bea02af57eba3b87803086d90b5e7657a57b528b89b1aa25f2f"}}'; |
||||
const account = new Account(); |
||||
account.fromFile(keystore, passphrase).then(account => { |
||||
console.log(account.bech32Address); |
||||
}); |
||||
``` |
||||
|
||||
Get the account balance |
||||
```javascript |
||||
const account = new Account( |
||||
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e', |
||||
new Messenger( |
||||
new HttpProvider('https://api.s0.b.hmny.io'), |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
), |
||||
); |
||||
account.getBalance().then(response => { |
||||
console.log(response); |
||||
}); |
||||
``` |
||||
outputs `{ balance: '9126943763247054940484', nonce: 45, shardID: 0 }` |
||||
|
||||
Create a transaction and account, and sign it |
||||
```javascript |
||||
const account = new Account( |
||||
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e', |
||||
new Messenger( |
||||
new HttpProvider('https://api.s0.b.hmny.io'), |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
), |
||||
); |
||||
const { TransactionFactory } = require('@woop-js/transaction'); |
||||
const { Unit } = require('@woop-js/utils'); |
||||
const factory = new TransactionFactory(); |
||||
|
||||
const txn = factory.newTx({ |
||||
to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2', |
||||
value: new Unit(1).asOne().toWei(), |
||||
// gas limit, you can use string |
||||
gasLimit: '21000', |
||||
// send token from shardID |
||||
shardID: 0, |
||||
// send token to toShardID |
||||
toShardID: 0, |
||||
// gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN |
||||
gasPrice: new Unit('1').asGwei().toWei(), |
||||
}); |
||||
|
||||
account.signTransaction(txn).then((signedTxn) => { |
||||
console.log(signedTxn); |
||||
}); |
||||
``` |
||||
|
||||
Similarily staking transactions can be created and signed using account. |
||||
|
||||
A wallet represents user wallet that can hold one or more user accounts. |
||||
|
||||
Creating an empty wallet |
||||
```javascript |
||||
const { Wallet } = require('@woop-js/account') |
||||
const wallet = new Wallet(); |
||||
``` |
||||
|
||||
Setting a messenger to be used to send wallet transactions |
||||
```javascript |
||||
wallet.setMessenger( |
||||
new Messenger( |
||||
new HttpProvider('https://api.s0.b.hmny.io'), |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
), |
||||
); |
||||
``` |
||||
|
||||
Create an empty wallet with messenger |
||||
```javascript |
||||
const wallet = new Wallet( |
||||
new Messenger( |
||||
new HttpProvider('https://api.s0.b.hmny.io'), |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
), |
||||
); |
||||
``` |
||||
|
||||
An account could be added to a wallet using different ways. Adding account using mnemonics |
||||
```javascript |
||||
const mnemonics = 'horse distance dry brother pretty manual chicken mushroom town swim prize clutch'; |
||||
const account = wallet.addByMnemonic(mnemonics); |
||||
``` |
||||
|
||||
Adding account using private key |
||||
```javascript |
||||
const account = wallet.addByPrivateKey('0x676cd9773dd23a4c1d7f22767c61c7b6723cc6be37b078545f6e0e91433a23dd') |
||||
``` |
||||
|
||||
Adding account using keystore file |
||||
```javascript |
||||
const keystore = '{"version":3,"id":"33363566-3564-4264-a638-363531666335","address":"7c41e0668b551f4f902cfaec05b5bdca68b124ce","crypto":{"ciphertext":"9b09380afb742838b32d9afc0ec1a3df35dbd7a41e3a160d08c07a4d0e79b855","cipherparams":{"iv":"1cd0e0522260eef055b9170f4825f4a0"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"salt":"bf35e36c45cccefcef73a4c900f41c682c94c28630d94d2d1f764760d245f30b","n":8192,"r":8,"p":1,"dklen":32},"mac":"25b4442972356bea02af57eba3b87803086d90b5e7657a57b528b89b1aa25f2f"}}'; |
||||
const passphrase = ''; |
||||
wallet.addByKeyStore(keystore, passphrase).then(account => { |
||||
console.log(account.bech32Address); |
||||
}); |
||||
``` |
||||
|
||||
Creating a new account using passphrase |
||||
```javascript |
||||
const passphrase = 'woop-chain'; |
||||
wallet.createAccount(passphrase).then(account => { |
||||
console.log(account.bech32Address); |
||||
}); |
||||
``` |
||||
|
||||
Get all accounts in the wallet |
||||
```javascript |
||||
wallet.accounts.forEach(addr => { |
||||
const account = wallet.getAccount(addr); |
||||
console.log(account.bech32Address); |
||||
}); |
||||
``` |
||||
|
||||
Set wallet signer when multiple accounts exists in the wallet |
||||
```javascript |
||||
wallet.setSigner(signerAddr); |
||||
``` |
||||
|
||||
Sign transaction using wallet, will sign the transaction using the wallet signer |
||||
```javascript |
||||
const txn = factory.newTx({ |
||||
to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2', |
||||
value: new Unit(1).asOne().toWei(), |
||||
// gas limit, you can use string |
||||
gasLimit: '21000', |
||||
// send token from shardID |
||||
shardID: 0, |
||||
// send token to toShardID |
||||
toShardID: 0, |
||||
// gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN |
||||
gasPrice: new Unit('1').asGwei().toWei(), |
||||
}); |
||||
|
||||
wallet.signTransaction(txn).then((signedTxn) => { |
||||
console.log(signedTxn); |
||||
}); |
||||
``` |
||||
|
||||
Similarily staking transactions can be signed using `signStaking` api. |
@ -0,0 +1,218 @@ |
||||
/** |
||||
# @woop-js/account |
||||
|
||||
This package provides a collection of apis to create accounts and wallets and sign using them. A wallet can hold multiple accounts and account is associated with a unique `one` address. This package also provides facilies to manage account keys. |
||||
|
||||
## Installation |
||||
|
||||
``` |
||||
npm install @woop-js/account |
||||
``` |
||||
|
||||
## Usage |
||||
|
||||
Creating new account and display hex and bech32 (one) addresses
|
||||
```javascript
|
||||
const account = new Account(); // or const account = Account.new()
|
||||
console.log(account.checksumAddress); |
||||
console.log(account.bech32Address); |
||||
``` |
||||
|
||||
Creating new account using private key |
||||
```javascript
|
||||
const account = Account.add('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'); |
||||
``` |
||||
|
||||
Creating account using private key and custom messenger |
||||
```javascript
|
||||
* const account = new Account( |
||||
* '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e', |
||||
* new Messenger( |
||||
* new HttpProvider('https://api.s0.b.hmny.io'), |
||||
* ChainType.Woop, |
||||
* ChainID.WikiTestnet, |
||||
* ), |
||||
* ); |
||||
``` |
||||
|
||||
Creating account and setting custom messenger |
||||
```javascript
|
||||
// uses by default http://localhost:9500 as messenger
|
||||
* const account = new Account(); |
||||
* const customMessenger = new Messenger( |
||||
* new HttpProvider('https://api.s0.b.hmny.io'), |
||||
* ChainType.Woop, |
||||
* ChainID.WikiTestnet, |
||||
* ); |
||||
|
||||
account.setMessenger(customMessenger); |
||||
``` |
||||
|
||||
Storing the account data to keystore file |
||||
```javascript
|
||||
* const passphrase = ''; |
||||
* const account = new Account('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'); |
||||
* account.toFile(passphrase).then(keystore => { |
||||
* console.log(keystore); |
||||
* }); |
||||
``` |
||||
|
||||
Fetching account from keystore file |
||||
```javascript
|
||||
* const passphrase = ''; |
||||
* const keystore = '{"version":3,"id":"33363566-3564-4264-a638-363531666335","address":"7c41e0668b551f4f902cfaec05b5bdca68b124ce","crypto":{"ciphertext":"9b09380afb742838b32d9afc0ec1a3df35dbd7a41e3a160d08c07a4d0e79b855","cipherparams":{"iv":"1cd0e0522260eef055b9170f4825f4a0"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"salt":"bf35e36c45cccefcef73a4c900f41c682c94c28630d94d2d1f764760d245f30b","n":8192,"r":8,"p":1,"dklen":32},"mac":"25b4442972356bea02af57eba3b87803086d90b5e7657a57b528b89b1aa25f2f"}}'; |
||||
* const account = new Account(); |
||||
* account.fromFile(keystore, passphrase).then(account => { |
||||
* console.log(account.bech32Address); |
||||
* }); |
||||
``` |
||||
|
||||
Get the account balance |
||||
```javascript
|
||||
* const account = new Account( |
||||
* '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e', |
||||
* new Messenger( |
||||
* new HttpProvider('https://api.s0.b.hmny.io'), |
||||
* ChainType.Woop, |
||||
* ChainID.WikiTestnet, |
||||
* ), |
||||
* ); |
||||
* account.getBalance().then(response => { |
||||
* console.log(response); |
||||
* }); |
||||
``` |
||||
outputs `{ balance: '9126943763247054940484', nonce: 45, shardID: 0 }` |
||||
|
||||
Create a transaction and account, and sign it |
||||
```javascript
|
||||
* const account = new Account( |
||||
* '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e', |
||||
* new Messenger( |
||||
* new HttpProvider('https://api.s0.b.hmny.io'), |
||||
* ChainType.Woop, |
||||
* ChainID.WikiTestnet, |
||||
* ), |
||||
* ); |
||||
* const { TransactionFactory } = require('@woop-js/transaction'); |
||||
* const { Unit } = require('@woop-js/utils'); |
||||
* const factory = new TransactionFactory(); |
||||
|
||||
* const txn = factory.newTx({ |
||||
* to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2', |
||||
* value: new Unit(1).asOne().toWei(), |
||||
* // gas limit, you can use string
|
||||
* gasLimit: '21000', |
||||
* // send token from shardID
|
||||
* shardID: 0, |
||||
* // send token to toShardID
|
||||
* toShardID: 0, |
||||
* // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
|
||||
* gasPrice: new Unit('1').asGwei().toWei(), |
||||
* }); |
||||
|
||||
* account.signTransaction(txn).then((signedTxn) => { |
||||
* console.log(signedTxn); |
||||
* }); |
||||
``` |
||||
|
||||
Similarily staking transactions can be created and signed using account. |
||||
|
||||
A wallet represents user wallet that can hold one or more user accounts. |
||||
|
||||
Creating an empty wallet |
||||
```javascript
|
||||
* const { Wallet } = require('@woop-js/account') |
||||
* const wallet = new Wallet(); |
||||
``` |
||||
|
||||
Setting a messenger to be used to send wallet transactions |
||||
```javascript
|
||||
* wallet.setMessenger( |
||||
* new Messenger( |
||||
* new HttpProvider('https://api.s0.b.hmny.io'), |
||||
* ChainType.Woop, |
||||
* ChainID.WikiTestnet, |
||||
* ), |
||||
* ); |
||||
``` |
||||
|
||||
Create an empty wallet with messenger |
||||
```javascript
|
||||
* const wallet = new Wallet( |
||||
* new Messenger( |
||||
* new HttpProvider('https://api.s0.b.hmny.io'), |
||||
* ChainType.Woop, |
||||
* ChainID.WikiTestnet, |
||||
* ), |
||||
* ); |
||||
``` |
||||
|
||||
An account could be added to a wallet using different ways. Adding account using mnemonics |
||||
```javascript
|
||||
const mnemonics = 'horse distance dry brother pretty manual chicken mushroom town swim prize clutch'; |
||||
const account = wallet.addByMnemonic(mnemonics); |
||||
``` |
||||
|
||||
Adding account using private key |
||||
```javascript
|
||||
const account = wallet.addByPrivateKey('0x676cd9773dd23a4c1d7f22767c61c7b6723cc6be37b078545f6e0e91433a23dd') |
||||
``` |
||||
|
||||
Adding account using keystore file |
||||
```javascript
|
||||
* const keystore = '{"version":3,"id":"33363566-3564-4264-a638-363531666335","address":"7c41e0668b551f4f902cfaec05b5bdca68b124ce","crypto":{"ciphertext":"9b09380afb742838b32d9afc0ec1a3df35dbd7a41e3a160d08c07a4d0e79b855","cipherparams":{"iv":"1cd0e0522260eef055b9170f4825f4a0"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"salt":"bf35e36c45cccefcef73a4c900f41c682c94c28630d94d2d1f764760d245f30b","n":8192,"r":8,"p":1,"dklen":32},"mac":"25b4442972356bea02af57eba3b87803086d90b5e7657a57b528b89b1aa25f2f"}}'; |
||||
* const passphrase = ''; |
||||
* wallet.addByKeyStore(keystore, passphrase).then(account => { |
||||
* console.log(account.bech32Address); |
||||
* }); |
||||
``` |
||||
|
||||
Creating a new account using passphrase |
||||
```javascript
|
||||
* const passphrase = 'woop-chain'; |
||||
* wallet.createAccount(passphrase).then(account => { |
||||
* console.log(account.bech32Address); |
||||
* }); |
||||
``` |
||||
|
||||
Get all accounts in the wallet |
||||
```javascript
|
||||
* wallet.accounts.forEach(addr => { |
||||
* const account = wallet.getAccount(addr); |
||||
* console.log(account.bech32Address); |
||||
* }); |
||||
``` |
||||
|
||||
Set wallet signer when multiple accounts exists in the wallet |
||||
```javascript
|
||||
wallet.setSigner(signerAddr); |
||||
``` |
||||
|
||||
Sign transaction using wallet, will sign the transaction using the wallet signer |
||||
```javascript
|
||||
* const txn = factory.newTx({ |
||||
* to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2', |
||||
* value: new Unit(1).asOne().toWei(), |
||||
* // gas limit, you can use string
|
||||
* gasLimit: '21000', |
||||
* // send token from shardID
|
||||
* shardID: 0, |
||||
* // send token to toShardID
|
||||
* toShardID: 0, |
||||
* // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
|
||||
* gasPrice: new Unit('1').asGwei().toWei(), |
||||
* }); |
||||
|
||||
* wallet.signTransaction(txn).then((signedTxn) => { |
||||
* console.log(signedTxn); |
||||
* }); |
||||
``` |
||||
|
||||
Similarily staking transactions can be signed using `signStaking` api. |
||||
*
|
||||
* @packageDocumentation |
||||
* @module woop-account |
||||
*/ |
||||
|
||||
/**@ignore */ |
||||
export interface README {} |
@ -0,0 +1,29 @@ |
||||
{ |
||||
"name": "@woop-js/account", |
||||
"version": "0.1.58", |
||||
"description": "account and wallet for woop", |
||||
"main": "dist/index.js", |
||||
"node": "dist/index.js", |
||||
"browser": "dist/index.js", |
||||
"module": "dist/index.esm.js", |
||||
"jsnext:main": "dist/index.esm.js", |
||||
"typings": "dist/index.d.ts", |
||||
"types": "dist/index.d.ts", |
||||
"scripts": { |
||||
"test": "echo \"Error: no test specified\" && exit 1" |
||||
}, |
||||
"publishConfig": { |
||||
"access": "public" |
||||
}, |
||||
"author": "neeboo@firestack.one", |
||||
"license": "MIT", |
||||
"dependencies": { |
||||
"@woop-js/core": "0.1.58", |
||||
"@woop-js/crypto": "0.1.58", |
||||
"@woop-js/network": "0.1.58", |
||||
"@woop-js/staking": "0.1.58", |
||||
"@woop-js/transaction": "0.1.58", |
||||
"@woop-js/utils": "0.1.58" |
||||
}, |
||||
"gitHead": "56606e9365721729a490c27d6a294e0daf90fbdf" |
||||
} |
@ -1,3 +1,9 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-account |
||||
* @ignore |
||||
*/ |
||||
|
||||
export * from './account'; |
||||
export * from './wallet'; |
||||
export * from './types'; |
@ -1,3 +1,9 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-account |
||||
* @hidden |
||||
*/ |
||||
|
||||
/** |
||||
* test type docs |
||||
*/ |
@ -0,0 +1,14 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-account |
||||
* @hidden |
||||
*/ |
||||
|
||||
import { HttpProvider, Messenger } from '@woop-js/network'; |
||||
import { ChainType, ChainID } from '@woop-js/utils'; |
||||
|
||||
export const defaultMessenger = new Messenger( |
||||
new HttpProvider('http://localhost:9500'), |
||||
ChainType.Woop, |
||||
ChainID.WikiLocal, |
||||
); |
@ -0,0 +1,36 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-account |
||||
* @ignore |
||||
*/ |
||||
|
||||
import fetch from 'jest-fetch-mock'; |
||||
import { Account } from '../src/account'; |
||||
import { HttpProvider, Messenger } from '@woop-js/network'; |
||||
import { ChainType, ChainID } from '@woop-js/utils'; |
||||
|
||||
const provider = new HttpProvider('http://localhost:9500'); |
||||
const messenger = new Messenger(provider, ChainType.Woop, ChainID.WikiLocal); |
||||
|
||||
describe('test account', () => { |
||||
it('test Account.getBalance returns object that implements Balance interface', () => { |
||||
fetch.mockResponses( |
||||
[ |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "0x166c690f33421e"}), |
||||
{ status: 200 } |
||||
], |
||||
[ |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "0x106"}), |
||||
{ status: 200 } |
||||
] |
||||
); |
||||
const acc = Account.new(); |
||||
acc.setMessenger(messenger); |
||||
acc.getBalance().then((res) => { |
||||
expect(res).not.toBeNull(); |
||||
expect(res.balance).not.toBeNull(); |
||||
expect(res.nonce).not.toBeNull(); |
||||
expect(res.shardID).not.toBeNull(); |
||||
}); |
||||
}); |
||||
}); |
@ -0,0 +1,15 @@ |
||||
{ |
||||
"extends": "../../tsconfig.base.json", |
||||
"compilerOptions": { |
||||
"rootDir": "src", |
||||
"outDir": "dist" |
||||
}, |
||||
"include": ["src", "../../typings/**/*.d.ts", "aaa.ts"], |
||||
"references": [ |
||||
{ "path": "../woop-crypto" }, |
||||
{ "path": "../woop-utils" }, |
||||
{ "path": "../woop-transaction" }, |
||||
{ "path": "../woop-staking" }, |
||||
{ "path": "../woop-network" } |
||||
] |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,147 @@ |
||||
# @woop-js/contract |
||||
|
||||
This package provides a collection of apis to create, deploy, and interact with smart contracts. In Woop, smart contracts all fully EVM compatible and the formats and terminologies match 1-to-1 with EVM smart contracts. |
||||
|
||||
## Installation |
||||
|
||||
``` |
||||
npm install @woop-js/contract |
||||
``` |
||||
|
||||
## Usage |
||||
|
||||
Deploying a contract using `contractConstructor` |
||||
```javascript |
||||
const { ContractFactory } = require('@woop-js/contract'); |
||||
const { Wallet } = require('@woop-js/account'); |
||||
const { Messenger, HttpProvider } = require('@woop-js/network'); |
||||
const { ChainID, ChainType, hexToNumber } = require('@woop-js/utils'); |
||||
|
||||
const wallet = new Wallet( |
||||
new Messenger( |
||||
new HttpProvider('https://api.s0.b.hmny.io'), |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
), |
||||
); |
||||
const factory = new ContractFactory(wallet); |
||||
|
||||
const contractJson = require("./Counter.json"); |
||||
const contract = factory.createContract(contractJson.abi); |
||||
|
||||
const options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000 |
||||
let options2 = { gasPrice: 1000000000, gasLimit: 21000 }; // setting the default gas limit, but changing later based on estimate gas |
||||
|
||||
const options3 = { data: contractJson.bytecode }; // contractConstructor needs contract bytecode to deploy |
||||
|
||||
contract.wallet.addByPrivateKey('1f054c21a0f57ebc402c00e14bd1707ddf45542d4ed9989933dbefc4ea96ca68'); |
||||
|
||||
contract.methods.contractConstructor(options3).estimateGas(options1).then(gas => { |
||||
options2 = {...options2, gasLimit: hexToNumber(gas)}; |
||||
contract.methods.contractConstructor(options3).send(options2).then(response => { |
||||
console.log('contract deployed at ' + response.transaction.receipt.contractAddress); |
||||
}); |
||||
}); |
||||
``` |
||||
Instead of `contract.methods.contractConstructor`, `contract.deploy` could be used and it will work. |
||||
|
||||
Loading a contract object using the contract json and contract address for interacting with it |
||||
```javascript |
||||
const { Woop } = require("@woop-js/core"); |
||||
const { ChainID, ChainType } = require("@woop-js/utils"); |
||||
const wiki = new Woop("https://api.s0.b.hmny.io", { |
||||
chainType: ChainType.Woop, |
||||
chainId: ChainID.WikiTestnet, |
||||
}); |
||||
|
||||
const contractJson = require("./Counter.json"); |
||||
const contractAddr = "0x19f64050e6b2d376e52AC426E366c49EEb0724B1"; |
||||
|
||||
const contract = wiki.contracts.createContract(contractJson.abi, contractAddr); |
||||
console.log(contract.methods); |
||||
``` |
||||
|
||||
Directly loading contract using `ContractFactory` |
||||
```javascript |
||||
const { ContractFactory } = require('@woop-js/contract'); |
||||
const { Wallet } = require('@woop-js/account'); |
||||
const { Messenger, HttpProvider } = require('@woop-js/network'); |
||||
const { ChainID, ChainType, hexToNumber } = require('@woop-js/utils'); |
||||
|
||||
const wallet = new Wallet(new Messenger( |
||||
new HttpProvider('https://api.s0.b.hmny.io'), |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
)); |
||||
const factory = new ContractFactory(wallet); |
||||
const contract = factory.createContract(contractJson.abi, contractAddr); |
||||
``` |
||||
|
||||
Estimate gas for contract methods |
||||
```javascript |
||||
const options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000 |
||||
|
||||
contract.methods.getCount().estimateGas(options1).then(gas => { |
||||
console.log('gas required for getCount is ' + hexToNumber(gas)); |
||||
}); |
||||
``` |
||||
|
||||
Call contract read-only methods. Woop uses 1 Gwei gas price and gas limit of 21000 by default. Use the estimate gas api to correctly set the gas limit. |
||||
```javascript |
||||
const options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000 |
||||
let options2 = { gasPrice: 1000000000, gasLimit: 21000 }; // setting the default gas limit, but changing later based on estimate gas |
||||
|
||||
contract.methods.getCount().estimateGas(options1).then(gas => { |
||||
options2 = {...options2, gasLimit: hexToNumber(gas)}; |
||||
contract.methods.getCount().call(options2).then(count => { |
||||
console.log('counter value: ' + count); |
||||
}); |
||||
}); |
||||
``` |
||||
|
||||
Invoking contract modification methods using `send` api. Need to add a signing account to the contract wallet, otherwise `send` api will not work. |
||||
```javascript |
||||
const options1 = { gasPrice: '0x3B9ACA00' }; // gas price in hex corresponds to 1 Gwei or 1000000000 |
||||
let options2 = { gasPrice: 1000000000, gasLimit: 21000 }; // setting the default gas limit, but changing later based on estimate gas |
||||
|
||||
contract.wallet.addByPrivateKey('1f054c21a0f57ebc402c00e14bd1707ddf45542d4ed9989933dbefc4ea96ca68'); |
||||
|
||||
contract.methods.incrementCounter().estimateGas(options1).then(gas => { |
||||
options2 = {...options2, gasLimit: hexToNumber(gas)}; |
||||
contract.methods.incrementCounter().send(options2).then(response => { |
||||
console.log(response.transaction.receipt); |
||||
}); |
||||
}); |
||||
``` |
||||
|
||||
All the above apis can also be asynchronously executed using `async` and `await`. |
||||
|
||||
Subscribing to the contract events requires web socket based messenger. |
||||
```javascript |
||||
const { ContractFactory } = require('@woop-js/contract'); |
||||
const { Wallet } = require('@woop-js/account'); |
||||
const { Messenger, WSProvider } = require('@woop-js/network'); |
||||
const { ChainID, ChainType, hexToNumber } = require('@woop-js/utils'); |
||||
const ws = new WSProvider('wss://ws.s0.b.hmny.io'); |
||||
|
||||
const wallet = new Wallet( |
||||
new Messenger( |
||||
ws, |
||||
ChainType.Woop, |
||||
ChainID.WikiTestnet, |
||||
), |
||||
); |
||||
const factory = new ContractFactory(wallet); |
||||
|
||||
const contractJson = require("./Counter.json"); |
||||
const contractAddr = '0x8ada52172abda19b9838eb00498a40952be6a019'; |
||||
|
||||
const contract = factory.createContract(contractJson.abi, contractAddr); |
||||
|
||||
contract.events |
||||
.IncrementedBy() |
||||
.on('data', (event) => { |
||||
console.log(event); |
||||
}) |
||||
.on('error', console.error); |
||||
``` |
@ -1,3 +1,9 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
import { AbiCoderClass } from './api'; |
||||
import { AbiCoder as EtherCoder } from './abiCoder'; |
||||
|
@ -1,4 +1,9 @@ |
||||
import { Wallet } from '@harmony-js/account'; |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
*/ |
||||
|
||||
import { Wallet } from '@woop-js/account'; |
||||
import { Contract } from './contract'; |
||||
import { ContractOptions } from './utils/options'; |
||||
|
@ -1,4 +1,9 @@ |
||||
import { LogSub } from '@harmony-js/network'; |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
*/ |
||||
|
||||
import { LogSub } from '@woop-js/network'; |
||||
import { AbiItemModel } from '../models/types'; |
||||
import { Contract } from '../contract'; |
||||
import { decode as eventLogDecoder } from '../utils/decoder'; |
@ -0,0 +1,11 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
export * from './abi/index'; |
||||
export { toUtf8Bytes, toUtf8String, formatBytes32String, parseBytes32String } from './abi/abiCoder'; |
||||
|
||||
export { Contract } from './contract'; |
||||
export { ContractFactory } from './contractFactory'; |
@ -1,4 +1,10 @@ |
||||
import { isArray } from '@harmony-js/utils'; |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
import { isArray } from '@woop-js/utils'; |
||||
import { AbiItemModel, AbiOutput, AbiInput } from './types'; |
||||
|
||||
export class AbiItem { |
@ -1,3 +1,9 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
// defined by web3.js
|
||||
// fixed
|
||||
export interface AbiModel { |
@ -1,11 +1,13 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
import { AbiItemModel } from '../models/types'; |
||||
import { AbiCoderClass } from '../abi/api'; |
||||
|
||||
export const decode = ( |
||||
abiCoder: AbiCoderClass, |
||||
abiItemModel: AbiItemModel, |
||||
response: any, |
||||
) => { |
||||
export const decode = (abiCoder: AbiCoderClass, abiItemModel: AbiItemModel, response: any) => { |
||||
let argumentTopics = response.topics; |
||||
|
||||
if (!abiItemModel.anonymous) { |
@ -1,3 +1,9 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
export interface ContractOptions { |
||||
data?: string; |
||||
shardID?: number; |
@ -1,3 +1,9 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
export enum ContractStatus { |
||||
INITIALISED = 'initialised', |
||||
TESTED = 'tested', |
@ -1,6 +1,11 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @ignore |
||||
*/ |
||||
|
||||
import { AbiCoder } from '../src/abi/abiCoder'; |
||||
import { BN } from '@harmony-js/crypto'; |
||||
import { isArray } from '@harmony-js/utils'; |
||||
import { BN } from '@woop-js/crypto'; |
||||
import { isArray } from '@woop-js/utils'; |
||||
import { abis } from './fixtures/abiv2'; |
||||
|
||||
function getValues(object: any, format?: any, named?: any): any { |
File diff suppressed because one or more lines are too long
@ -0,0 +1,164 @@ |
||||
# @woop-js/core |
||||
|
||||
This package provides a collection of apis to interact with Woop blockchain. |
||||
|
||||
## Installation |
||||
|
||||
``` |
||||
npm install @woop-js/core |
||||
``` |
||||
|
||||
## Usage |
||||
|
||||
Create a Woop instance connecting to testnet |
||||
|
||||
```javascript |
||||
const { Woop } = require('@woop-js/core'); |
||||
const { |
||||
ChainID, |
||||
ChainType, |
||||
hexToNumber, |
||||
numberToHex, |
||||
fromWei, |
||||
Units, |
||||
Unit, |
||||
} = require('@woop-js/utils'); |
||||
|
||||
const wiki = new Woop( |
||||
'https://api.s0.b.hmny.io/', |
||||
{ |
||||
chainType: ChainType.Woop, |
||||
chainId: ChainID.WikiTestnet, |
||||
}, |
||||
); |
||||
``` |
||||
|
||||
Getting balance of account `one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7` |
||||
```javascript |
||||
wiki.blockchain |
||||
.getBalance({ address: 'one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7' }) |
||||
.then((response) => { |
||||
console.log('balance in ONEs: ' + fromWei(hexToNumber(response.result), Units.one)); |
||||
}); |
||||
``` |
||||
|
||||
Getting the latest block number |
||||
```javascript |
||||
wiki.blockchain.getBlockNumber().then((response) => { |
||||
console.log('current block number: ' + hexToNumber(response.result)); |
||||
}); |
||||
``` |
||||
|
||||
Getting the block using block hash |
||||
```javascript |
||||
wiki.blockchain |
||||
.getBlockByHash({ |
||||
blockHash: '0x08c46ae7249362a7d1f602d44c5a81f33ebdab6a7dcb6068f99610b57911aafd', |
||||
}) |
||||
.then((response) => { |
||||
console.log(response.result); |
||||
}); |
||||
``` |
||||
|
||||
Getting the block using block number |
||||
```javascript |
||||
wiki.blockchain |
||||
.getBlockByNumber({ |
||||
blockNumber: numberToHex(422635), |
||||
}) |
||||
.then((response) => { |
||||
console.log(response.result); |
||||
}); |
||||
``` |
||||
|
||||
Getting the transaction using hash |
||||
```javascript |
||||
wiki.blockchain |
||||
.getTransactionByHash({ |
||||
txnHash: '0x56c73eb993b18dc04baacec5c2e9d1292a090f6a978a4a1c461db5255fcbc831', |
||||
}) |
||||
.then((response) => { |
||||
console.log(response.result); |
||||
}); |
||||
``` |
||||
|
||||
Getting the transaction receipt |
||||
```javascript |
||||
wiki.blockchain |
||||
.getTransactionReceipt({ |
||||
txnHash: '0x56c73eb993b18dc04baacec5c2e9d1292a090f6a978a4a1c461db5255fcbc831', |
||||
}) |
||||
.then((response) => { |
||||
console.log(response.result); |
||||
}); |
||||
``` |
||||
|
||||
Getting the cross-shard transaction receipt |
||||
```javascript |
||||
wiki.blockchain |
||||
.getCxReceiptByHash({ |
||||
txnHash: '0xcd36a90ff5d5373285c2896ba7bbcd3f5324263c0cb8ecfb7cad2f5fc2fbdbda', |
||||
shardID: 1, |
||||
}) |
||||
.then((value) => { |
||||
console.log(value.result); |
||||
}); |
||||
``` |
||||
|
||||
Getting the deployed smart contract code |
||||
```javascript |
||||
wiki.blockchain |
||||
.getCode({ |
||||
address: '0x08AE1abFE01aEA60a47663bCe0794eCCD5763c19', |
||||
blockNumber: 'latest', |
||||
}) |
||||
.then((response) => { |
||||
console.log(response.result); |
||||
}); |
||||
``` |
||||
|
||||
Getting the transaction count of an account |
||||
```javascript |
||||
wiki.blockchain |
||||
.getTransactionCount({ |
||||
address: 'one1pdv9lrdwl0rg5vglh4xtyrv3wjk3wsqket7zxy', |
||||
}) |
||||
.then((response) => { |
||||
console.log(hexToNumber(response.result)); |
||||
}); |
||||
``` |
||||
|
||||
Getting the shard structure and details |
||||
```javascript |
||||
wiki.blockchain.getShardingStructure().then((response) => { |
||||
console.log(response.result); |
||||
}); |
||||
``` |
||||
|
||||
Transferring funds using `sendTransaction` |
||||
```javascript |
||||
// key corresponds to one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7, only has testnet balance |
||||
wiki.wallet.addByPrivateKey('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'); |
||||
|
||||
async function transfer() { |
||||
const txn = wiki.transactions.newTx({ |
||||
to: 'one166axnkjmghkf3df7xfvd0hn4dft8kemrza4cd2', |
||||
value: new Unit(1).asOne().toWei(), |
||||
// gas limit, you can use string |
||||
gasLimit: '21000', |
||||
// send token from shardID |
||||
shardID: 0, |
||||
// send token to toShardID |
||||
toShardID: 0, |
||||
// gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN |
||||
gasPrice: new wiki.utils.Unit('1').asGwei().toWei(), |
||||
}); |
||||
|
||||
// sign the transaction use wallet; |
||||
const signedTxn = await wiki.wallet.signTransaction(txn); |
||||
const txnHash = await wiki.blockchain.sendTransaction(signedTxn); |
||||
console.log(txnHash.result); |
||||
} |
||||
|
||||
transfer(); |
||||
``` |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,11 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-core |
||||
* @hidden |
||||
*/ |
||||
|
||||
export * from './woop'; |
||||
export * from './blockchain'; |
||||
export * from './truffleProvider'; |
||||
export * from './woopExtension'; |
||||
export * from './types'; |
@ -0,0 +1,31 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-core |
||||
* @hidden |
||||
*/ |
||||
|
||||
import { HttpProvider, Messenger } from '@woop-js/network'; |
||||
import { TransactionFactory, Transaction } from '@woop-js/transaction'; |
||||
import { Wallet, Account } from '@woop-js/account'; |
||||
import { ChainType, ChainID } from '@woop-js/utils'; |
||||
import { Blockchain } from './blockchain'; |
||||
|
||||
export interface WoopModule { |
||||
HttpProvider: HttpProvider; |
||||
Messenger: Messenger; |
||||
Blockchain: Blockchain; |
||||
TransactionFactory: TransactionFactory; |
||||
Wallet: Wallet; |
||||
Transaction: Transaction; |
||||
Account: Account; |
||||
} |
||||
|
||||
export enum UrlType { |
||||
http, |
||||
ws, |
||||
} |
||||
|
||||
export interface WoopSetting<T extends ChainType, I extends ChainID> { |
||||
type: T; |
||||
id: I; |
||||
} |
@ -0,0 +1,229 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-core |
||||
*/ |
||||
|
||||
import * as crypto from '@woop-js/crypto'; |
||||
import * as utils from '@woop-js/utils'; |
||||
|
||||
import { Provider, HttpProvider, Messenger, WSProvider, ShardingItem } from '@woop-js/network'; |
||||
import { TransactionFactory, Transaction } from '@woop-js/transaction'; |
||||
import { StakingTransaction, StakingFactory } from '@woop-js/staking'; |
||||
import { ContractFactory, Contract } from '@woop-js/contract'; |
||||
import { Wallet, Account } from '@woop-js/account'; |
||||
import { Blockchain } from './blockchain'; |
||||
import { WoopConfig } from './util'; |
||||
|
||||
export class Woop extends utils.WoopCore { |
||||
/**@ignore*/ |
||||
Modules = { |
||||
HttpProvider, |
||||
WSProvider, |
||||
Messenger, |
||||
Blockchain, |
||||
TransactionFactory, |
||||
StakingFactory, |
||||
Wallet, |
||||
Transaction, |
||||
StakingTransaction, |
||||
Account, |
||||
Contract, |
||||
}; |
||||
/**@ignore*/ |
||||
messenger: Messenger; |
||||
/**@ignore*/ |
||||
transactions: TransactionFactory; |
||||
/**@ignore*/ |
||||
stakings: StakingFactory; |
||||
/**@ignore*/ |
||||
wallet: Wallet; |
||||
/**@ignore*/ |
||||
blockchain: Blockchain; |
||||
/**@ignore*/ |
||||
contracts: ContractFactory; |
||||
/**@ignore*/ |
||||
crypto: any; |
||||
/**@ignore*/ |
||||
utils: any; |
||||
/**@ignore*/ |
||||
defaultShardID?: number; |
||||
/**@ignore*/ |
||||
private provider: HttpProvider | WSProvider; |
||||
|
||||
/** |
||||
* Create a woop instance |
||||
* |
||||
* @param url The end-points of the wiki blockchain |
||||
* @param config set up `ChainID` and `ChainType`, typically we can use the default values |
||||
* |
||||
* @example |
||||
* ``` |
||||
* // import or require Woop class
|
||||
* const { Woop } = require('@woop-js/core'); |
||||
* |
||||
* // import or require settings
|
||||
* const { ChainID, ChainType } = require('@woop-js/utils'); |
||||
* |
||||
* // Initialize the Woop instance
|
||||
* const wiki = new Woop( |
||||
* // rpc url:
|
||||
* // local: http://localhost:9500
|
||||
* // testnet: https://api.s0.b.hmny.io/
|
||||
* // mainnet: https://api.s0.t.hmny.io/
|
||||
* 'http://localhost:9500', |
||||
* { |
||||
* // chainType set to Woop
|
||||
* chainType: ChainType.Woop, |
||||
* // chainType set to WikiLocal
|
||||
* chainId: ChainID.WikiLocal, |
||||
* }, |
||||
* ); |
||||
* ``` |
||||
*/ |
||||
constructor( |
||||
url: string, |
||||
config: WoopConfig = { |
||||
chainId: utils.defaultConfig.Default.Chain_ID, |
||||
chainType: utils.defaultConfig.Default.Chain_Type, |
||||
}, |
||||
) { |
||||
super(config.chainType, config.chainId); |
||||
|
||||
const providerUrl = config.chainUrl || url || utils.defaultConfig.Default.Chain_URL; |
||||
|
||||
this.provider = new Provider(providerUrl).provider; |
||||
this.messenger = new Messenger(this.provider, this.chainType, this.chainId); |
||||
this.blockchain = new Blockchain(this.messenger); |
||||
this.transactions = new TransactionFactory(this.messenger); |
||||
this.stakings = new StakingFactory(this.messenger); |
||||
this.wallet = new Wallet(this.messenger); |
||||
this.contracts = new ContractFactory(this.wallet); |
||||
this.crypto = crypto; |
||||
this.utils = utils; |
||||
this.defaultShardID = config.shardID; |
||||
if (this.defaultShardID !== undefined) { |
||||
this.setShardID(this.defaultShardID); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Will change the provider for its module.
|
||||
* |
||||
* @param provider a valid provider, you can replace it with your own working node |
||||
* |
||||
* @example |
||||
* ```javascript
|
||||
* const tmp = wiki.setProvider('http://localhost:9500'); |
||||
* ``` |
||||
*/ |
||||
public setProvider(provider: string | HttpProvider | WSProvider): void { |
||||
this.provider = new Provider(provider).provider; |
||||
this.messenger.setProvider(this.provider); |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
|
||||
/** |
||||
* set the chainID |
||||
*
|
||||
* @hint |
||||
* ``` |
||||
* Default = 0, |
||||
* EthMainnet = 1, |
||||
Morden = 2, |
||||
Ropsten = 3, |
||||
Rinkeby = 4, |
||||
RootstockMainnet = 30, |
||||
RootstockTestnet = 31, |
||||
Kovan = 42, |
||||
EtcMainnet = 61, |
||||
EtcTestnet = 62, |
||||
Geth = 1337, |
||||
Ganache = 0, |
||||
WikiMainnet = 1, |
||||
WikiTestnet = 2, |
||||
WikiLocal = 2, |
||||
WikiPangaea = 3 |
||||
* ``` |
||||
* @param chainId
|
||||
*
|
||||
* @example |
||||
* ``` |
||||
* wiki.setChainId(2); |
||||
* ``` |
||||
*/ |
||||
public setChainId(chainId: utils.ChainID) { |
||||
this.chainId = chainId; |
||||
this.messenger.setChainId(this.chainId); |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
|
||||
/** |
||||
* Change the Shard ID |
||||
* |
||||
* @example |
||||
* ``` |
||||
* wiki.setShardID(2); |
||||
* ``` |
||||
*/ |
||||
public setShardID(shardID: number) { |
||||
this.defaultShardID = shardID; |
||||
this.messenger.setDefaultShardID(this.defaultShardID); |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
|
||||
/** |
||||
* set the chainType |
||||
* |
||||
* @param chainType `wiki` or `eth` |
||||
* |
||||
* @example |
||||
* ``` |
||||
* // set chainType to wiki
|
||||
* wiki.setChainType('wiki'); |
||||
* // set chainType to eth
|
||||
* wiki.setChainType('eth'); |
||||
* ``` |
||||
*/ |
||||
public setChainType(chainType: utils.ChainType) { |
||||
this.chainType = chainType; |
||||
this.messenger.setChainType(this.chainType); |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
|
||||
/** |
||||
* Set the sharding Structure |
||||
* |
||||
* @param shardingStructures The array of information of sharding structures |
||||
* |
||||
* @example |
||||
* ```javascript
|
||||
* wiki.shardingStructures([ |
||||
* {"current":true,"http":"http://127.0.0.1:9500", |
||||
* "shardID":0,"ws":"ws://127.0.0.1:9800"}, |
||||
* {"current":false,"http":"http://127.0.0.1:9501", |
||||
* "shardID":1,"ws":"ws://127.0.0.1:9801"} |
||||
* ]); |
||||
* ``` |
||||
*/ |
||||
public shardingStructures(shardingStructures: ShardingItem[]) { |
||||
for (const shard of shardingStructures) { |
||||
const shardID = |
||||
typeof shard.shardID === 'string' ? Number.parseInt(shard.shardID, 10) : shard.shardID; |
||||
this.messenger.shardProviders.set(shardID, { |
||||
current: shard.current !== undefined ? shard.current : false, |
||||
shardID, |
||||
http: shard.http, |
||||
ws: shard.ws, |
||||
}); |
||||
} |
||||
this.setMessenger(this.messenger); |
||||
} |
||||
|
||||
/**@ignore*/ |
||||
private setMessenger(messenger: Messenger) { |
||||
this.blockchain.setMessenger(messenger); |
||||
this.wallet.setMessenger(messenger); |
||||
this.transactions.setMessenger(messenger); |
||||
this.stakings.setMessenger(messenger); |
||||
} |
||||
} |
@ -0,0 +1,16 @@ |
||||
{ |
||||
"extends": "../../tsconfig.base.json", |
||||
"compilerOptions": { |
||||
"rootDir": "src", |
||||
"outDir": "dist" |
||||
}, |
||||
"include": ["src", "../../typings/**/*.d.ts", "../woop-utils/src/core.ts"], |
||||
"references": [ |
||||
{"path": "../woop-account"}, |
||||
{"path": "../woop-crypto"}, |
||||
{"path": "../woop-utils"}, |
||||
{"path": "../woop-network"}, |
||||
{"path": "../woop-transaction"}, |
||||
{"path": "../woop-contract"} |
||||
] |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue