Skip to content

Commit 4f357bc

Browse files
authored
Merge pull request #6085 from BitGo/COIN-3996-fetch-sdk-cosmos-batch
feat(sdk-coin-fetch): add SDK Skeleton for Fetch
2 parents ad6eef7 + 2990b21 commit 4f357bc

29 files changed

+434
-0
lines changed

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
/modules/sdk-coin-cspr/ @BitGo/ethalt-team
6262
/modules/sdk-coin-dot/ @BitGo/ethalt-team
6363
/modules/sdk-coin-eos/ @BitGo/ethalt-team
64+
/modules/sdk-coin-fetch/ @BitGo/ethalt-team
6465
/modules/sdk-coin-flr/ @BitGo/ethalt-team
6566
/modules/sdk-coin-ethlike/ @BitGo/ethalt-team
6667
/modules/sdk-coin-hbar/ @BitGo/ethalt-team

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-cronos /var/modules/sdk-coin-cro
7676
COPY --from=builder /tmp/bitgo/modules/sdk-coin-cspr /var/modules/sdk-coin-cspr/
7777
COPY --from=builder /tmp/bitgo/modules/sdk-coin-dot /var/modules/sdk-coin-dot/
7878
COPY --from=builder /tmp/bitgo/modules/sdk-coin-etc /var/modules/sdk-coin-etc/
79+
COPY --from=builder /tmp/bitgo/modules/sdk-coin-fetch /var/modules/sdk-coin-fetch/
7980
COPY --from=builder /tmp/bitgo/modules/sdk-coin-flr /var/modules/sdk-coin-flr/
8081
COPY --from=builder /tmp/bitgo/modules/sdk-coin-hash /var/modules/sdk-coin-hash/
8182
COPY --from=builder /tmp/bitgo/modules/sdk-coin-hbar /var/modules/sdk-coin-hbar/
@@ -166,6 +167,7 @@ cd /var/modules/sdk-coin-cronos && yarn link && \
166167
cd /var/modules/sdk-coin-cspr && yarn link && \
167168
cd /var/modules/sdk-coin-dot && yarn link && \
168169
cd /var/modules/sdk-coin-etc && yarn link && \
170+
cd /var/modules/sdk-coin-fetch && yarn link && \
169171
cd /var/modules/sdk-coin-flr && yarn link && \
170172
cd /var/modules/sdk-coin-hash && yarn link && \
171173
cd /var/modules/sdk-coin-hbar && yarn link && \
@@ -259,6 +261,7 @@ RUN cd /var/bitgo-express && \
259261
yarn link @bitgo/sdk-coin-cspr && \
260262
yarn link @bitgo/sdk-coin-dot && \
261263
yarn link @bitgo/sdk-coin-etc && \
264+
yarn link @bitgo/sdk-coin-fetch && \
262265
yarn link @bitgo/sdk-coin-flr && \
263266
yarn link @bitgo/sdk-coin-hash && \
264267
yarn link @bitgo/sdk-coin-hbar && \

modules/account-lib/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@bitgo/sdk-coin-dot": "^4.1.56",
4646
"@bitgo/sdk-coin-etc": "^2.2.45",
4747
"@bitgo/sdk-coin-eth": "^24.4.1",
48+
"@bitgo/sdk-coin-fetch": "^1.0.0",
4849
"@bitgo/sdk-coin-flr": "^1.2.2",
4950
"@bitgo/sdk-coin-hash": "^3.0.47",
5051
"@bitgo/sdk-coin-hbar": "^2.0.78",

modules/account-lib/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ export { Mantra };
113113
import * as Cronos from '@bitgo/sdk-coin-cronos';
114114
export { Cronos };
115115

116+
import * as Fetch from '@bitgo/sdk-coin-fetch';
117+
export { Fetch };
118+
116119
import * as Sol from '@bitgo/sdk-coin-sol';
117120
export { Sol };
118121

@@ -263,6 +266,8 @@ const coinBuilderMap = {
263266
tbaby: Baby.TransactionBuilder,
264267
cronos: Cronos.TransactionBuilder,
265268
tcronos: Cronos.TransactionBuilder,
269+
fetch: Fetch.TransactionBuilder,
270+
tfetch: Fetch.TransactionBuilder,
266271
flr: Flr.TransactionBuilder,
267272
tflr: Flr.TransactionBuilder,
268273
sgb: Sgb.TransactionBuilder,

modules/bitgo/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"@bitgo/sdk-coin-eth": "^24.4.1",
7979
"@bitgo/sdk-coin-ethlike": "^1.2.13",
8080
"@bitgo/sdk-coin-ethw": "^20.0.78",
81+
"@bitgo/sdk-coin-fetch": "^1.0.0",
8182
"@bitgo/sdk-coin-flr": "^1.2.2",
8283
"@bitgo/sdk-coin-hash": "^3.0.47",
8384
"@bitgo/sdk-coin-hbar": "^2.0.78",

modules/bitgo/src/v2/coinFactory.ts

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
Eth,
4848
Ethw,
4949
EthLikeCoin,
50+
Fetch,
5051
Flr,
5152
TethLikeCoin,
5253
FiatAED,
@@ -117,6 +118,7 @@ import {
117118
Teos,
118119
Tetc,
119120
Teth,
121+
Tfetch,
120122
Tflr,
121123
Tmon,
122124
TfiatAED,
@@ -211,6 +213,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
211213
globalCoinFactory.register('fiatgbp', FiatGBP.createInstance);
212214
globalCoinFactory.register('fiatsgd', FiatSGD.createInstance);
213215
globalCoinFactory.register('fiatusd', FiatUsd.createInstance);
216+
globalCoinFactory.register('fetch', Fetch.createInstance);
214217
globalCoinFactory.register('flr', Flr.createInstance);
215218
globalCoinFactory.register('gteth', Gteth.createInstance);
216219
globalCoinFactory.register('hash', Hash.createInstance);
@@ -277,6 +280,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
277280
globalCoinFactory.register('tfiatgbp', TfiatGBP.createInstance);
278281
globalCoinFactory.register('tfiatsgd', TfiatSGD.createInstance);
279282
globalCoinFactory.register('tfiatusd', TfiatUsd.createInstance);
283+
globalCoinFactory.register('tfetch', Tfetch.createInstance);
280284
globalCoinFactory.register('tflr', Tflr.createInstance);
281285
globalCoinFactory.register('tmon', Tmon.createInstance);
282286
globalCoinFactory.register('thash', Thash.createInstance);

modules/bitgo/src/v2/coins/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { Dot, Tdot } from '@bitgo/sdk-coin-dot';
2727
import { Eos, EosToken, Teos } from '@bitgo/sdk-coin-eos';
2828
import { Etc, Tetc } from '@bitgo/sdk-coin-etc';
2929
import { Erc20Token, Eth, Gteth, Hteth, Teth } from '@bitgo/sdk-coin-eth';
30+
import { Fetch, Tfetch } from '@bitgo/sdk-coin-fetch';
3031
import { Flr, Tflr } from '@bitgo/sdk-coin-flr';
3132
import { Ethw } from '@bitgo/sdk-coin-ethw';
3233
import { EthLikeCoin, TethLikeCoin } from '@bitgo/sdk-coin-ethlike';
@@ -97,6 +98,7 @@ export { Erc20Token, Eth, Gteth, Hteth, Teth };
9798
export { Ethw };
9899
export { EthLikeCoin, TethLikeCoin };
99100
export { Etc, Tetc };
101+
export { Fetch, Tfetch };
100102
export { Flr, Tflr };
101103
export { Hash, Thash };
102104
export { Hbar, Thbar };

modules/bitgo/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@
146146
{
147147
"path": "../sdk-coin-ethw"
148148
},
149+
{
150+
"path": "../sdk-coin-fetch"
151+
},
149152
{
150153
"path": "../sdk-coin-flr"
151154
},

modules/sdk-coin-fetch/.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.idea
3+
public
4+
dist

modules/sdk-coin-fetch/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
.idea/
3+
dist/

modules/sdk-coin-fetch/.mocharc.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require: 'ts-node/register'
2+
timeout: '60000'
3+
reporter: 'min'
4+
reporter-option:
5+
- 'cdn=true'
6+
- 'json=false'
7+
exit: true
8+
spec: ['test/unit/**/*.ts']

modules/sdk-coin-fetch/.npmignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
!dist/
2+
dist/test/
3+
dist/tsconfig.tsbuildinfo
4+
.idea/
5+
.prettierrc.yml
6+
tsconfig.json
7+
src/
8+
test/
9+
scripts/
10+
.nyc_output
11+
CODEOWNERS
12+
node_modules/
13+
.prettierignore
14+
.mocharc.js
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.nyc_output/
2+
dist/
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
printWidth: 120
2+
singleQuote: true
3+
trailingComma: 'es5'

modules/sdk-coin-fetch/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# BitGo sdk-coin-fetch
2+
3+
SDK coins provide a modular approach to a monolithic architecture. This and all BitGoJS SDK coins allow developers to use only the coins needed for a given project.
4+
5+
## Installation
6+
7+
All coins are loaded traditionally through the `bitgo` package. If you are using coins individually, you will be accessing the coin via the `@bitgo/sdk-api` package.
8+
9+
In your project install both `@bitgo/sdk-api` and `@bitgo/sdk-coin-fetch`.
10+
11+
```shell
12+
npm i @bitgo/sdk-api @bitgo/sdk-coin-fetch
13+
```
14+
15+
Next, you will be able to initialize an instance of "bitgo" through `@bitgo/sdk-api` instead of `bitgo`.
16+
17+
```javascript
18+
import { BitGoAPI } from '@bitgo/sdk-api';
19+
import { Fetch } from '@bitgo/sdk-coin-fetch';
20+
21+
const sdk = new BitGoAPI();
22+
23+
sdk.register('fetch', Fetch.createInstance);
24+
```
25+
26+
## Development
27+
28+
Most of the coin implementations are derived from `@bitgo/sdk-core`, `@bitgo/statics`, and coin specific packages. These implementations are used to interact with the BitGo API and BitGo platform services.
29+
30+
You will notice that the basic version of common class extensions have been provided to you and must be resolved before the package build will succeed. Upon initiation of a given SDK coin, you will need to verify that your coin has been included in the root `tsconfig.packages.json` and that the linting, formatting, and testing succeeds when run both within the coin and from the root of BitGoJS.

modules/sdk-coin-fetch/package.json

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@bitgo/sdk-coin-fetch",
3+
"version": "1.0.0",
4+
"description": "BitGo SDK coin library for Fetch",
5+
"main": "./dist/src/index.js",
6+
"types": "./dist/src/index.d.ts",
7+
"scripts": {
8+
"build": "yarn tsc --build --incremental --verbose .",
9+
"fmt": "prettier --write .",
10+
"check-fmt": "prettier --check .",
11+
"clean": "rm -r ./dist",
12+
"lint": "eslint --quiet .",
13+
"prepare": "npm run build",
14+
"test": "npm run coverage",
15+
"coverage": "nyc -- npm run unit-test",
16+
"unit-test": "mocha"
17+
},
18+
"author": "BitGo SDK Team <sdkteam@bitgo.com>",
19+
"license": "MIT",
20+
"engines": {
21+
"node": ">=18 <21"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/BitGo/BitGoJS.git",
26+
"directory": "modules/sdk-coin-fetch"
27+
},
28+
"lint-staged": {
29+
"*.{js,ts}": [
30+
"yarn prettier --write",
31+
"yarn eslint --fix"
32+
]
33+
},
34+
"publishConfig": {
35+
"access": "public"
36+
},
37+
"nyc": {
38+
"extension": [
39+
".ts"
40+
]
41+
},
42+
"dependencies": {
43+
"@bitgo/abstract-cosmos": "^11.7.2",
44+
"@bitgo/sdk-core": "^33.1.0",
45+
"@bitgo/statics": "^52.1.0",
46+
"@cosmjs/stargate": "^0.29.5"
47+
},
48+
"devDependencies": {
49+
"@bitgo/sdk-api": "^1.62.2",
50+
"@bitgo/sdk-test": "^8.0.83"
51+
}
52+
}

modules/sdk-coin-fetch/src/fetch.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
2+
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
3+
import { CosmosCoin, CosmosKeyPair, GasAmountDetails } from '@bitgo/abstract-cosmos';
4+
import { TransactionBuilderFactory } from './lib';
5+
6+
export class Fetch extends CosmosCoin {
7+
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
8+
9+
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
10+
super(bitgo, staticsCoin);
11+
12+
if (!staticsCoin) {
13+
throw new Error('missing required constructor parameter staticsCoin');
14+
}
15+
16+
this._staticsCoin = staticsCoin;
17+
}
18+
19+
static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
20+
return new Fetch(bitgo, staticsCoin);
21+
}
22+
23+
/** @inheritDoc **/
24+
getBaseFactor(): number {
25+
return Math.pow(10, this._staticsCoin.decimalPlaces);
26+
}
27+
28+
/** @inheritDoc **/
29+
getBuilder(): TransactionBuilderFactory {
30+
throw new Error('Method not implemented.');
31+
}
32+
33+
/** @inheritDoc **/
34+
isValidAddress(address: string): boolean {
35+
throw new Error('Method not implemented.');
36+
}
37+
38+
/** @inheritDoc **/
39+
getDenomination(): string {
40+
throw new Error('Method not implemented');
41+
}
42+
43+
/** @inheritDoc **/
44+
getGasAmountDetails(): GasAmountDetails {
45+
throw new Error('Method not implemented');
46+
}
47+
48+
/** @inheritDoc **/
49+
getKeyPair(publicKey: string): CosmosKeyPair {
50+
throw new Error('Method not implemented');
51+
}
52+
53+
/** @inheritDoc **/
54+
protected getPublicNodeUrl(): string {
55+
throw new Error('Method not implemented');
56+
}
57+
58+
/** @inheritDoc **/
59+
getAddressFromPublicKey(pubKey: string): string {
60+
throw new Error('Method not implemented');
61+
}
62+
}

modules/sdk-coin-fetch/src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './lib';
2+
export * from './register';
3+
export * from './fetch';
4+
export * from './tfetch';

modules/sdk-coin-fetch/src/lib/constants.ts

Whitespace-only changes.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Utils from './utils';
2+
3+
export {
4+
CosmosTransaction as Transaction,
5+
CosmosTransactionBuilder as TransactionBuilder,
6+
} from '@bitgo/abstract-cosmos';
7+
export { KeyPair } from './keyPair';
8+
export { TransactionBuilderFactory } from './transactionBuilderFactory';
9+
export { Utils };
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { KeyPairOptions } from '@bitgo/sdk-core';
2+
import { CosmosKeyPair } from '@bitgo/abstract-cosmos';
3+
4+
/**
5+
* Fetch keys and address management.
6+
*/
7+
export class KeyPair extends CosmosKeyPair {
8+
constructor(source?: KeyPairOptions) {
9+
super(source);
10+
}
11+
12+
/** @inheritdoc */
13+
getAddress(): string {
14+
throw new Error('Method not implemented.');
15+
}
16+
}

0 commit comments

Comments
 (0)