Skip to content

Commit 3ff6179

Browse files
james-hummingbotCrimsonJacket
authored andcommitted
Fork of ethers so it is compatible with XDC and doesn't interfere with existing code (#3)
* Drop patch packages * Update build files * Update vendor packages for building * ethers-xdc is building * It compiles * try again * Still trying * fix * clean up
1 parent 626e7b6 commit 3ff6179

File tree

1,488 files changed

+126989
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,488 files changed

+126989
-254
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ certs
22
*.md
33
*.yml
44
coverage
5-
dist
5+
dist
6+
vendor

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"dayjs": "^1.10.6",
6565
"decimal.js-light": "^2.5.1",
6666
"ethers": "^5.6.2",
67+
"ethers-xdc": "file:./vendor/ethers-xdc",
6768
"express": "^4.17.1",
6869
"express-winston": "^4.1.0",
6970
"fs-extra": "^10.0.0",
@@ -73,14 +74,8 @@
7374
"mathjs": "^10.5.0",
7475
"minimist": "^1.2.6",
7576
"morgan": "^1.10.0",
76-
<<<<<<< HEAD
77-
"patch-package": "^6.4.7",
78-
"postinstall-postinstall": "^2.1.0",
79-
=======
8077
"near-api-js": "1.0.0",
81-
>>>>>>> e41c04384 (Drop patch packages)
8278
"quickswap-sdk": "^3.0.8",
83-
"near-api-js": "1.0.0",
8479
"swagger-ui-express": "^4.1.6",
8580
"tslib": "^2.3.1",
8681
"uuid": "^8.3.2",

src/chains/xdc/xdc.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import abi from '../ethereum/ethereum.abi.json';
22
import { logger } from '../../services/logger';
33
import { Contract, Transaction, Wallet } from 'ethers';
4+
import { providers } from 'ethers-xdc';
5+
46
import { EthereumBase } from '../ethereum/ethereum-base';
57
import { getEthereumConfig as getXdcConfig } from '../ethereum/ethereum.config';
68
import { Provider } from '@ethersproject/abstract-provider';
79
import { XdcswapConfig } from '../../connectors/xdcswap/xdcswap.config';
810
import { Ethereumish } from '../../services/common-interfaces';
911
import { ConfigManagerV2 } from '../../services/config-manager-v2';
1012
import { walletPath } from '../../services/base';
11-
import { convertEthAddressToXdcAddress, convertXdxAddressToEthAddress } from '../../services/wallet/wallet.controllers';
13+
import {
14+
convertEthAddressToXdcAddress,
15+
convertXdxAddressToEthAddress,
16+
} from '../../services/wallet/wallet.controllers';
1217
import fse from 'fs-extra';
1318
import { ConfigManagerCertPassphrase } from '../../services/config-manager-cert-passphrase';
1419

@@ -17,6 +22,7 @@ export class Xdc extends EthereumBase implements Ethereumish {
1722
private _gasPrice: number;
1823
private _nativeTokenSymbol: string;
1924
private _chain: string;
25+
private _xdcProvider: providers.Provider;
2026

2127
private constructor(network: string) {
2228
const config = getXdcConfig('xdc', network);
@@ -34,6 +40,9 @@ export class Xdc extends EthereumBase implements Ethereumish {
3440
this._chain = config.network.name;
3541
this._nativeTokenSymbol = config.nativeCurrencySymbol;
3642
this._gasPrice = config.manualGasPrice;
43+
this._xdcProvider = new providers.StaticJsonRpcProvider(
44+
config.network.nodeURL
45+
);
3746
}
3847

3948
public static getInstance(network: string): Xdc {
@@ -101,6 +110,35 @@ export class Xdc extends EthereumBase implements Ethereumish {
101110
return await this.decrypt(encryptedPrivateKey, passphrase);
102111
}
103112

113+
async getTransaction(txHash: string): Promise<providers.TransactionResponse> {
114+
console.log('this._xdcProvider.getTransaction');
115+
return this._xdcProvider.getTransaction(txHash);
116+
}
117+
118+
// returns an ethereum TransactionReceipt for a txHash if the transaction has been mined.
119+
async getTransactionReceipt(
120+
txHash: string
121+
): Promise<providers.TransactionReceipt | null> {
122+
if (this.cache.keys().includes(txHash)) {
123+
// If it's in the cache, return the value in cache, whether it's null or not
124+
return this.cache.get(txHash) as providers.TransactionReceipt;
125+
} else {
126+
// If it's not in the cache,
127+
const fetchedTxReceipt = await this._xdcProvider.getTransactionReceipt(
128+
txHash
129+
);
130+
131+
this.cache.set(txHash, fetchedTxReceipt); // Cache the fetched receipt, whether it's null or not
132+
133+
if (!fetchedTxReceipt) {
134+
this._xdcProvider.once(txHash, this.cacheTransactionReceipt.bind(this));
135+
}
136+
137+
return fetchedTxReceipt;
138+
}
139+
}
140+
141+
104142
async close() {
105143
await super.close();
106144
if (this._chain in Xdc._instances) {

src/network/network.routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export namespace NetworkRoutes {
8989
req.body.chain,
9090
req.body.network
9191
);
92+
console.log(chain.chainName);
9293

9394
res.status(200).json(await ethereumControllers.poll(chain, req.body));
9495
}

vendor/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
**/node_modules
3+
**/lib._esm
4+
obsolete/
5+
.DS_Store
6+
.tmp/
7+
**/src.ts/*.js
8+
**/tsconfig.tsbuildinfo
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
tsconfig.json
3+
lib._esm
4+
tsconfig.tsbuildinfo
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Richard Moore
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Ethereum ABI Coder
2+
==================
3+
4+
This sub-module is part of the [ethers project](https://github.com/ethers-io/ethers.js).
5+
6+
It is responsible for encoding and decoding the Application Binary Interface (ABI)
7+
used by most smart contracts to interoperate between other smart contracts and clients.
8+
9+
For more information, see the [documentation](https://docs.ethers.io/v5/api/utils/abi/).
10+
11+
Importing
12+
---------
13+
14+
Most users will prefer to use the [umbrella package](https://www.npmjs.com/package/ethers),
15+
but for those with more specific needs, individual components can be imported.
16+
17+
```javascript
18+
const {
19+
20+
ConstructorFragment,
21+
EventFragment,
22+
Fragment,
23+
FunctionFragment,
24+
ParamType,
25+
FormatTypes,
26+
27+
AbiCoder,
28+
defaultAbiCoder,
29+
30+
Interface,
31+
Indexed,
32+
33+
/////////////////////////
34+
// Types
35+
36+
CoerceFunc,
37+
JsonFragment,
38+
JsonFragmentType,
39+
40+
Result,
41+
checkResultErrors,
42+
43+
LogDescription,
44+
TransactionDescription
45+
46+
} = require("@ethersproject-xdc/abi");
47+
```
48+
49+
License
50+
-------
51+
52+
MIT License
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export declare const version = "abi/5.7.0";
2+
//# sourceMappingURL=_version.d.ts.map

vendor/@ethersproject-xdc/abi/lib.esm/_version.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)