Compare commits
No commits in common. 'master' and 'datastructure-update' have entirely different histories.
master
...
datastruct
@ -0,0 +1,5 @@ |
||||
GENESIS_PRIV_KEY=45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e |
||||
HTTP_PROVIDER=http://localhost:9500 |
||||
CHAIN_TYPE=hmy |
||||
CHAIN_ID=2 |
||||
|
@ -1,70 +0,0 @@ |
||||
# 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 |
||||
``` |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,100 +0,0 @@ |
||||
# 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,169 +1,88 @@ |
||||
import fetch from 'jest-fetch-mock'; |
||||
import { woop, checkCalledMethod } from './woop'; |
||||
import {harmony} from './harmony'; |
||||
|
||||
import demoAccounts from '../fixtures/testAccount.json'; |
||||
import { RPCMethod } from '@woop-js/network'; |
||||
|
||||
const bc = woop.blockchain; |
||||
const bc = harmony.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(checkCalledMethod(0, RPCMethod.PeerCount)).toEqual(true); |
||||
expect(woop.utils.isHex(peerCount.result)).toEqual(true); |
||||
expect(harmony.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 wiki_protocolVersion', async () => { |
||||
fetch.mockResponseOnce( |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "0x10"}), |
||||
); |
||||
it('should test hmy_protocolVersion', async () => { |
||||
const protocolVersion = await bc.getProtocolVersion(); |
||||
expect(woop.utils.isHex(protocolVersion.result)).toEqual(true); |
||||
expect(checkCalledMethod(0, RPCMethod.ProtocolVersion)).toEqual(true); |
||||
expect(harmony.utils.isHex(protocolVersion.result)).toEqual(true); |
||||
}); |
||||
|
||||
// block chain info
|
||||
it('should test wiki_blockNumber', async () => { |
||||
fetch.mockResponseOnce( |
||||
JSON.stringify({"jsonrpc": "2.0", "id": 1, "result": "0x10"}), |
||||
); |
||||
it('should test hmy_blockNumber', async () => { |
||||
const res = await bc.getBlockNumber(); |
||||
expect(res.responseType).toEqual('raw'); |
||||
expect(woop.utils.isHex(res.result)).toEqual(true); |
||||
expect(checkCalledMethod(0, RPCMethod.BlockNumber)).toEqual(true); |
||||
expect(harmony.utils.isHex(res.result)).toEqual(true); |
||||
}); |
||||
|
||||
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' }); |
||||
it('should test hmy_getBlockByNumber', async () => { |
||||
const res = await bc.getBlockByNumber({blockNumber: 'latest'}); |
||||
const size = res.result.size; |
||||
expect(res.responseType).toEqual('raw'); |
||||
expect(woop.utils.isHex(size)).toEqual(true); |
||||
expect(harmony.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(woop.utils.isHex(res2.result.size)).toEqual(true); |
||||
expect(harmony.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 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 }); |
||||
it('should test hmy_getBlockByHash', async () => { |
||||
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(woop.utils.isHex(res.result.size)).toEqual(true); |
||||
expect(harmony.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 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); |
||||
it('should test hmy_getBalance', async () => { |
||||
const balance = await bc.getBalance({address: testAccount.Address}); |
||||
expect(harmony.utils.isHex(balance.result)).toEqual(true); |
||||
}); |
||||
}); |
||||
|
||||
function checkBlockData(data: any) { |
||||
return woop.utils.validateArgs( |
||||
return harmony.utils.validateArgs( |
||||
data, |
||||
{ |
||||
difficulty: [woop.utils.isNumber], |
||||
difficulty: [harmony.utils.isNumber], |
||||
// tslint:disable-next-line: no-shadowed-variable
|
||||
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], |
||||
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], |
||||
}, |
||||
{ transactions: [woop.utils.isArray] }, |
||||
{transactions: [harmony.utils.isArray]}, |
||||
); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,29 @@ |
||||
// 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, |
||||
); |
@ -1,39 +0,0 @@ |
||||
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
@ -1,12 +0,0 @@ |
||||
# 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> |
@ -0,0 +1,9 @@ |
||||
# Usage |
||||
|
||||
```typescript |
||||
|
||||
import {Wallet} from '@harmony-js/account' |
||||
|
||||
const wallet=new Wallet() |
||||
|
||||
``` |
@ -1,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-account |
||||
* @ignore |
||||
*/ |
||||
|
||||
export * from './account'; |
||||
export * from './wallet'; |
||||
export * from './types'; |
@ -1,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-account |
||||
* @hidden |
||||
*/ |
||||
|
||||
/** |
||||
* test type docs |
||||
*/ |
@ -0,0 +1,8 @@ |
||||
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, |
||||
); |
@ -0,0 +1,15 @@ |
||||
{ |
||||
"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,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
import { AbiCoderClass } from './api'; |
||||
import { AbiCoder as EtherCoder } from './abiCoder'; |
||||
|
@ -1,9 +1,4 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
*/ |
||||
|
||||
import { Wallet } from '@woop-js/account'; |
||||
import { Wallet } from '@harmony-js/account'; |
||||
import { Contract } from './contract'; |
||||
import { ContractOptions } from './utils/options'; |
||||
|
@ -1,9 +1,4 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
*/ |
||||
|
||||
import { LogSub } from '@woop-js/network'; |
||||
import { LogSub } from '@harmony-js/network'; |
||||
import { AbiItemModel } from '../models/types'; |
||||
import { Contract } from '../contract'; |
||||
import { decode as eventLogDecoder } from '../utils/decoder'; |
@ -0,0 +1,10 @@ |
||||
export * from './abi/index'; |
||||
export { |
||||
toUtf8Bytes, |
||||
toUtf8String, |
||||
formatBytes32String, |
||||
parseBytes32String, |
||||
} from './abi/abiCoder'; |
||||
|
||||
export { Contract } from './contract'; |
||||
export { ContractFactory } from './contractFactory'; |
@ -1,10 +1,4 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
import { isArray } from '@woop-js/utils'; |
||||
import { isArray } from '@harmony-js/utils'; |
||||
import { AbiItemModel, AbiOutput, AbiInput } from './types'; |
||||
|
||||
export class AbiItem { |
@ -1,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
// defined by web3.js
|
||||
// fixed
|
||||
export interface AbiModel { |
@ -1,13 +1,11 @@ |
||||
/** |
||||
* @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,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
export interface ContractOptions { |
||||
data?: string; |
||||
shardID?: number; |
@ -1,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-contract |
||||
* @hidden |
||||
*/ |
||||
|
||||
export enum ContractStatus { |
||||
INITIALISED = 'initialised', |
||||
TESTED = 'tested', |
@ -1,11 +1,6 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @ignore |
||||
*/ |
||||
|
||||
import { AbiCoder } from '../src/abi/abiCoder'; |
||||
import { BN } from '@woop-js/crypto'; |
||||
import { isArray } from '@woop-js/utils'; |
||||
import { BN } from '@harmony-js/crypto'; |
||||
import { isArray } from '@harmony-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,526 @@ |
||||
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 }; |
@ -0,0 +1,99 @@ |
||||
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); |
||||
} |
||||
} |
@ -0,0 +1,5 @@ |
||||
export * from './harmony'; |
||||
export * from './blockchain'; |
||||
export * from './truffleProvider'; |
||||
export * from './harmonyExtension'; |
||||
export * from './types'; |
@ -0,0 +1,25 @@ |
||||
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; |
||||
} |
@ -0,0 +1,16 @@ |
||||
{ |
||||
"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"} |
||||
] |
||||
} |
@ -0,0 +1,80 @@ |
||||
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,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-crypto |
||||
* @ignore |
||||
*/ |
||||
|
||||
import hdkey from 'hdkey'; |
||||
import bip39 from 'bip39'; |
||||
import BN from 'bn.js'; |
@ -1,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-crypto |
||||
* @ignore |
||||
*/ |
||||
|
||||
// this file is ported from 'ether.js' and done some fixes
|
||||
import * as sha3 from 'js-sha3'; |
||||
|
@ -1,19 +1,18 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-crypto |
||||
*/ |
||||
|
||||
/** |
||||
* Uses JS-native CSPRNG to generate a specified number of bytes. |
||||
* @NOTE |
||||
* this method throws if no PRNG is available. |
||||
* @function randomBytes |
||||
* @description Uses JS-native CSPRNG to generate a specified number of bytes. |
||||
* NOTE: this method throws if no PRNG is available. |
||||
* @param {Number} bytes bytes number to generate |
||||
* @return {String} ramdom hex string |
||||
*/ |
||||
export const randomBytes = (bytes: number): string => { |
||||
let randBz: number[] | Uint8Array; |
||||
|
||||
if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) { |
||||
if ( |
||||
typeof window !== 'undefined' && |
||||
window.crypto && |
||||
window.crypto.getRandomValues |
||||
) { |
||||
randBz = window.crypto.getRandomValues(new Uint8Array(bytes)); |
||||
} else if (typeof require !== 'undefined') { |
||||
randBz = require('crypto').randomBytes(bytes); |
@ -1,8 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @ignore |
||||
*/ |
||||
|
||||
import * as bytes from '../src/bytes'; |
||||
|
||||
describe('Bytes', () => { |
@ -1,8 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @ignore |
||||
*/ |
||||
|
||||
import * as hash from '../src/keccak256'; |
||||
|
||||
import hashes from './fixtures/hashes.json'; |
@ -1,10 +1,5 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @ignore |
||||
*/ |
||||
|
||||
import * as keys from '../src/keyTool'; |
||||
import { isPrivateKey, isAddress, isPublicKey } from '@woop-js/utils'; |
||||
import { isPrivateKey, isAddress, isPublicKey } from '@harmony-js/utils'; |
||||
|
||||
describe('test keyTools', () => { |
||||
it('test keygen', () => { |
@ -1,8 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @ignore |
||||
*/ |
||||
|
||||
import * as rlp from '../src/rlp'; |
||||
import cases from './fixtures/rlpcoder.json'; |
||||
|
@ -1,9 +1,3 @@ |
||||
/** |
||||
* @packageDocumentation |
||||
* @module woop-network |
||||
* @ignore |
||||
*/ |
||||
|
||||
import mitt from 'mitt'; |
||||
export { mitt }; |
||||
// provider related
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue