Skip to content

Commit

Permalink
Update typescript type definition (#105)
Browse files Browse the repository at this point in the history
* add const ZERO_ADDRESS

* update typescript definition
  • Loading branch information
Pana authored Feb 18, 2021
1 parent 968e8e5 commit 9be7e51
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# change log

## v1.5.0
## v1.5.10

* `Conflux`'s option can pass `networkId` now, and add a new method `updateNetworkId` to sync networkId from RPC.
* `format.address` will return new CIP37 addresses, if you pass a hex address, `networkId` should also be passed as second parameter
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

JavaScript Conflux Software Development Kit

## 1.5 Key features
v1.5 add support for [CIP37](https://github.com/Conflux-Chain/CIPs/blob/master/CIPs/cip-37.md) address.
## 1.5.10 Key features
v1.5.10 add support for [CIP37](https://github.com/Conflux-Chain/CIPs/blob/master/CIPs/cip-37.md) address.
And only work with `conflux-rust v1.1.1` or above.

```sh
# For now you can install it with `next` tag
$ npm install js-conflux-sdk@next
```

The biggest difference you `must to know` is class `Conflux`'s init option add a new field `networkId`.
If you still want use hex40 address when invoke RPC methods, `networkId must be set`,
only with `networkId` conflux can firgure out a right CIP37 address from hex40 address.
Expand Down Expand Up @@ -91,10 +86,13 @@ or
</script>
```

CDN services such as `jsdelivr` provide link you can directly use for example:
https://cdn.jsdelivr.net/npm/js-conflux-sdk/dist/js-conflux-sdk.umd.min.js

## Documentation

* [Overview](./docs/overview.md)
* [Complete document for send transaction](./docs/how_to_send_tx.md)
* [Complete document for sending transaction](./docs/how_to_send_tx.md)
* [Interacting with contract](./docs/interact_with_contract.md)
* [SDK support for CIP37 address](./docs/conflux_checksum_address.md)
* [API](./docs/api.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Notice: one address can have two form `checksumed` and `not checksumed`, these t


### Send Transaction
For detail explanation of send transaction check [here](./how_to_send_tx.md)
Check [here](./how_to_send_tx.md) to know more details

### chainId
`chainId` is used to distinguish different network and prevent replay attack, currently:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-conflux-sdk",
"description": "JavaScript Conflux Software Development Kit",
"version": "1.5.9",
"version": "1.5.10",
"license": "LGPL-3.0",
"author": "[email protected]",
"repository": "https://github.com/Conflux-Chain/js-conflux-sdk.git",
Expand Down
14 changes: 12 additions & 2 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const TRANSACTION_STORAGE_LIMIT = 0;
*
* @type {number}
* > CONST.MAINNET_ID
0
1029
*/
const MAINNET_ID = 1029;

Expand All @@ -70,10 +70,19 @@ const MAINNET_ID = 1029;
*
* @type {number}
* > CONST.TESTNET_ID
0
1
*/
const TESTNET_ID = 1;

/**
* zero address
*
* @type {string}
* > ZERO_ADDRESS
0x0000000000000000000000000000000000000000
*/
const ZERO_ADDRESS_HEX = '0x0000000000000000000000000000000000000000';

module.exports = {
WORD_BYTES,
WORD_CHARS,
Expand All @@ -85,4 +94,5 @@ module.exports = {
TRANSACTION_STORAGE_LIMIT,
TESTNET_ID,
MAINNET_ID,
ZERO_ADDRESS_HEX,
};
3 changes: 3 additions & 0 deletions src/Conflux.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Contract = require('./contract');
const internalContract = require('./contract/internal');
const PendingTransaction = require('./subscribe/PendingTransaction');
const Subscription = require('./subscribe/Subscription');
const pkg = require('../package.json');

/**
* A sdk of conflux.
Expand Down Expand Up @@ -49,6 +50,8 @@ class Conflux {
useHexAddressInParameter = false,
...rest
} = {}) {
this.version = pkg.version;

/**
* Provider for rpc call
*
Expand Down
2 changes: 1 addition & 1 deletion src/util/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,6 @@ format.traces = format({

format.blockTraces = format({
transactionTraces: [format.traces],
});
}).$or(null);

module.exports = format;
12 changes: 10 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import JSBI from 'jsbi';

type JSBI = BigInt;
type EPOCH_LABEL = 'latest_mined' | 'latest_state' | 'latest_checkpoint' | 'latest_confirmed' | 'earliest';
type EpochNumber = number | EPOCH_LABEL;
type Address = string;
Expand All @@ -10,6 +9,7 @@ type Quantity = string | number | JSBI;
interface ConfluxOption {
url: string,
timeout?: number,
networkId?: number,
logger?: object,
defaultGasPrice?: number,
defaultGasRatio?: number,
Expand Down Expand Up @@ -96,6 +96,14 @@ export class Conflux {

getLogs(options: object): Promise<object[]>;

traceBlock(blockHash: string): Promise<object[]>;

getDepositList(address: string, epochNumber?: EpochNumber): Promise<object[]>;

getVoteList(address: string, epochNumber?: EpochNumber): Promise<object[]>;

getSupplyInfo(epochNumber: EpochNumber): Promise<object>;

// ----------------------------- subscription -------------------------------
subscribe(name: string, ...args: any[]): Promise<string>

Expand Down
9 changes: 8 additions & 1 deletion types/rpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export interface BlockHeader {
refereeHashes: string[];
size: number;
timestamp: number;
transactionsRoot: string
transactionsRoot: string;
gasUsed: string;
}

export interface Block extends BlockHeader {
Expand Down Expand Up @@ -115,6 +116,11 @@ export interface TransactionReceipt {
outcomeStatus: number;
logsBloom: string;
logs: CfxLog[];
storageCollateralized: string;
storageReleased: Object[];
txExecErrorMsg: string;
gasCoveredBySponsor: boolean;
storageCoveredBySponsor: boolean;
}

export interface Account {
Expand All @@ -125,4 +131,5 @@ export interface Account {
collateralForStorage: number;
accumulatedInterestReturn: number;
admin: Address;
address: Address;
}

0 comments on commit 9be7e51

Please sign in to comment.