-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-coin-lnbtc): add new sdk coin lnbtc module
sdk coin lnbtc module Ticket: BTC-1258
- Loading branch information
1 parent
fde27b2
commit cb9eed3
Showing
27 changed files
with
399 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.idea | ||
public | ||
dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
.idea/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require: 'ts-node/register' | ||
timeout: '60000' | ||
reporter: 'min' | ||
reporter-option: | ||
- 'cdn=true' | ||
- 'json=false' | ||
exit: true | ||
spec: ['test/unit/**/*.ts'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
!dist/ | ||
dist/test/ | ||
dist/tsconfig.tsbuildinfo | ||
.idea/ | ||
.prettierrc.yml | ||
tsconfig.json | ||
src/ | ||
test/ | ||
scripts/ | ||
.nyc_output | ||
CODEOWNERS | ||
node_modules/ | ||
.prettierignore | ||
.mocharc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.nyc_output/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
printWidth: 120 | ||
singleQuote: true | ||
trailingComma: 'es5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# BitGo sdk-coin-lnbtc | ||
|
||
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. | ||
|
||
## Installation | ||
|
||
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. | ||
|
||
In your project install both `@bitgo/sdk-api` and `@bitgo/sdk-coin-lnbtc`. | ||
|
||
```shell | ||
npm i @bitgo/sdk-api @bitgo/sdk-coin-lnbtc | ||
``` | ||
|
||
Next, you will be able to initialize an instance of "bitgo" through `@bitgo/sdk-api` instead of `bitgo`. | ||
|
||
```javascript | ||
import { BitGoAPI } from '@bitgo/sdk-api'; | ||
import { Lnbtc } from '@bitgo/sdk-coin-lnbtc'; | ||
|
||
const sdk = new BitGoAPI(); | ||
|
||
sdk.register('lnbtc', Lnbtc.createInstance); | ||
``` | ||
|
||
## Development | ||
|
||
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. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "@bitgo/sdk-coin-lnbtc", | ||
"version": "1.0.0", | ||
"description": "BitGo SDK coin library for LightningBitcoin", | ||
"main": "./dist/src/index.js", | ||
"types": "./dist/src/index.d.ts", | ||
"scripts": { | ||
"build": "yarn tsc --build --incremental --verbose .", | ||
"fmt": "prettier --write .", | ||
"check-fmt": "prettier --check .", | ||
"clean": "rm -r ./dist", | ||
"lint": "eslint --quiet .", | ||
"prepare": "npm run build", | ||
"test": "npm run coverage", | ||
"coverage": "nyc -- npm run unit-test", | ||
"unit-test": "mocha" | ||
}, | ||
"author": "BitGo SDK Team <[email protected]>", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=18 <21" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BitGo/BitGoJS.git", | ||
"directory": "modules/sdk-coin-lnbtc" | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts}": [ | ||
"yarn prettier --write", | ||
"yarn eslint --fix" | ||
] | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
] | ||
}, | ||
"dependencies": { | ||
"@bitgo/abstract-lightning": "^1.0.0", | ||
"@bitgo/sdk-core": "^27.1.0", | ||
"@bitgo/utxo-lib": "^9.38.0" | ||
}, | ||
"devDependencies": { | ||
"@bitgo/sdk-api": "^1.49.0", | ||
"@bitgo/sdk-test": "^8.0.24" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './lnbtc'; | ||
export * from './tlnbtc'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { AbstractLightningCoin } from '@bitgo/abstract-lightning'; | ||
import { BitGoBase, BaseCoin } from '@bitgo/sdk-core'; | ||
import * as utxolib from '@bitgo/utxo-lib'; | ||
|
||
export class Lnbtc extends AbstractLightningCoin { | ||
constructor(bitgo: BitGoBase, network?: utxolib.Network) { | ||
super(bitgo, network || utxolib.networks.bitcoin); | ||
} | ||
|
||
static createInstance(bitgo: BitGoBase): BaseCoin { | ||
return new Lnbtc(bitgo); | ||
} | ||
|
||
getChain(): string { | ||
return 'lnbtc'; | ||
} | ||
|
||
getFamily(): string { | ||
return 'lnbtc'; | ||
} | ||
|
||
getFullName(): string { | ||
return 'LightningBitcoin'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core'; | ||
import { Lnbtc } from './lnbtc'; | ||
import * as utxolib from '@bitgo/utxo-lib'; | ||
|
||
export class Tlnbtc extends Lnbtc { | ||
constructor(bitgo: BitGoBase) { | ||
super(bitgo, utxolib.networks.testnet); | ||
} | ||
|
||
static createInstance(bitgo: BitGoBase): BaseCoin { | ||
return new Tlnbtc(bitgo); | ||
} | ||
|
||
getChain(): string { | ||
return 'tlnbtc'; | ||
} | ||
|
||
getFullName(): string { | ||
return 'Testnet LightningBitcoin'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'should'; | ||
|
||
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test'; | ||
import { BitGoAPI } from '@bitgo/sdk-api'; | ||
|
||
import { Tlnbtc } from '../../src/index'; | ||
|
||
describe('LightningBitcoin', function () { | ||
let bitgo: TestBitGoAPI; | ||
let basecoin: Tlnbtc; | ||
|
||
before(function () { | ||
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' }); | ||
bitgo.safeRegister('tlnbtc', Tlnbtc.createInstance); | ||
bitgo.initializeTestVars(); | ||
basecoin = bitgo.coin('tlnbtc') as Tlnbtc; | ||
}); | ||
|
||
it('should instantiate the coin', function () { | ||
basecoin.should.be.an.instanceof(Tlnbtc); | ||
}); | ||
|
||
it('should return full name', function () { | ||
basecoin.getFullName().should.equal('Testnet LightningBitcoin'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "./", | ||
"strictPropertyInitialization": false, | ||
"esModuleInterop": true, | ||
"typeRoots": ["../../types", "./node_modules/@types", "../../node_modules/@types"] | ||
}, | ||
"include": ["src/**/*", "test/**/*"], | ||
"exclude": ["node_modules"], | ||
"references": [ | ||
{ | ||
"path": "../abstract-lightning" | ||
}, | ||
{ | ||
"path": "../sdk-api" | ||
}, | ||
{ | ||
"path": "../sdk-core" | ||
}, | ||
{ | ||
"path": "../sdk-test" | ||
}, | ||
{ | ||
"path": "../utxo-lib" | ||
} | ||
] | ||
} |
Oops, something went wrong.