Skip to content

Commit

Permalink
add sanitize logic to BatchRequester (Conflux-Chain#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pana authored May 16, 2024
1 parent fb3292b commit 72e25f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![npm](https://img.shields.io/npm/v/js-conflux-sdk.svg)](https://www.npmjs.com/package/js-conflux-sdk)
[![npm](https://img.shields.io/npm/dm/js-conflux-sdk.svg)](https://www.npmjs.com/package/js-conflux-sdk)

JavaScript Conflux Software Development Kit is a complete library for interacting with the [Conflux Blockchain Core Space](https://doc.confluxnetwork.org/docs/core/Overview) in both Node.js and browser environment.
JavaScript Conflux Software Development Kit is a complete library for interacting with the **[Conflux Blockchain Core Space](https://doc.confluxnetwork.org/docs/core/Overview)** in both Node.js and browser environment.

Featured with:

Expand All @@ -18,6 +18,8 @@ Featured with:
4. Type conversion
* Extensive documentation and examples

For the Conflux eSpace JS SDK, consider using one of the following robust libraries: [ethers.js](https://docs.ethers.org/v6/), [viem](https://viem.sh/), or [web3.js](https://web3js.readthedocs.io/en/v1.10.0/)

## Docs

* [js-conflux-sdk documentation](https://docs.confluxnetwork.org/js-conflux-sdk)
Expand All @@ -35,7 +37,7 @@ Featured with:
Install through npm

```sh
$ npm install js-conflux-sdk
npm install js-conflux-sdk
```

## How to import
Expand Down
7 changes: 7 additions & 0 deletions src/rpc/BatchRequester.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const RPCError = require('../provider/RPCError');
const Transaction = require('../Transaction');
const format = require('../util/format');

const SEND_TX_METHOD = 'cfx_sendTransaction';
const SEND_RAW_TX_METHOD = 'cfx_sendRawTransaction';
Expand Down Expand Up @@ -172,13 +173,19 @@ class BatchRequester {
}

_markNonceUsed(from, nonce) {
from = format.address(from, this.conflux.networkId);
nonce = format.bigUInt(nonce);

if (!this.accountUsedNonces[from]) {
this.accountUsedNonces[from] = {};
}
this.accountUsedNonces[from][nonce] = true;
}

_isNonceUsed(from, nonce) {
from = format.address(from, this.conflux.networkId);
nonce = format.bigUInt(nonce);

return this.accountUsedNonces[from] && this.accountUsedNonces[from][nonce];
}

Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -922,9 +922,9 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@conflux-dev/conflux-address-js@^1.3.16":
"@conflux-dev/[email protected]":
version "1.3.16"
resolved "https://registry.yarnpkg.com/@conflux-dev/conflux-address-js/-/conflux-address-js-1.3.16.tgz#2ae7733138fe160e177392d7e1dc5f27590d1ee6"
resolved "https://registry.npmmirror.com/@conflux-dev/conflux-address-js/-/conflux-address-js-1.3.16.tgz#2ae7733138fe160e177392d7e1dc5f27590d1ee6"
integrity sha512-9n7wFCr7Wu4WYdngPfxB63bRHSk+0xWFHVqVwUPddg3oIRT+sQm+TcHGiXaiuvnjnvjDFfCMbHnjZ+a8X5C/aA==
dependencies:
jsbi "^3.1.4"
Expand Down

0 comments on commit 72e25f8

Please sign in to comment.