-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(abstract-lightning): add custodial lightning api functions
split lightning wallet to self and custodial Ticket: BTC-0
- Loading branch information
1 parent
a8f5223
commit 0a0ce29
Showing
10 changed files
with
243 additions
and
194 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
modules/abstract-lightning/src/wallet/custodialLightning.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,13 @@ | ||
import { ILightningWallet, LightningWallet } from './lightning'; | ||
import * as sdkcore from '@bitgo/sdk-core'; | ||
|
||
export type ICustodialLightningWallet = ILightningWallet; | ||
|
||
export class CustodialLightningWallet extends LightningWallet implements ICustodialLightningWallet { | ||
constructor(wallet: sdkcore.IWallet) { | ||
super(wallet); | ||
if (wallet.type() !== 'custodial') { | ||
throw new Error(`Invalid lightning wallet type for custodial lightning: ${wallet.type()}`); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './lightning'; | ||
export * from './custodialLightning'; | ||
export * from './selfCustodialLightning'; | ||
export * from './wallet'; |
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
29 changes: 29 additions & 0 deletions
29
modules/abstract-lightning/src/wallet/selfCustodialLightning.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,29 @@ | ||
import * as sdkcore from '@bitgo/sdk-core'; | ||
import { BackupResponse } from '../codecs'; | ||
import { ILightningWallet, LightningWallet } from './lightning'; | ||
|
||
export interface ISelfCustodialLightningWallet extends ILightningWallet { | ||
/** | ||
* Get the channel backup for the given wallet. | ||
* @returns {Promise<BackupResponse>} A promise resolving to the channel backup | ||
*/ | ||
getChannelBackup(): Promise<BackupResponse>; | ||
} | ||
|
||
export class SelfCustodialLightningWallet extends LightningWallet implements ISelfCustodialLightningWallet { | ||
constructor(wallet: sdkcore.IWallet) { | ||
super(wallet); | ||
if (wallet.type() !== 'hot') { | ||
throw new Error(`Invalid lightning wallet type for self custodial lightning: ${wallet.type()}`); | ||
} | ||
} | ||
|
||
async getChannelBackup(): Promise<BackupResponse> { | ||
const backupResponse = await this.wallet.bitgo | ||
.get(this.wallet.baseCoin.url(`/wallet/${this.wallet.id()}/lightning/backup`)) | ||
.result(); | ||
return sdkcore.decodeOrElse(BackupResponse.name, BackupResponse, backupResponse, (error) => { | ||
throw new Error(`Invalid backup response: ${error}`); | ||
}); | ||
} | ||
} |
Oops, something went wrong.