New abstract structure
Events for invoices get emitted in rooms
This commit is contained in:
112
src/helper/backendProvider.ts
Normal file
112
src/helper/backendProvider.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { InvoiceManager } from './invoiceManager';
|
||||
import { CryptoUnits } from './types';
|
||||
|
||||
/**
|
||||
* This backend provider class is required to write your own backends.
|
||||
*
|
||||
* *By default LibrePay supports Bitcoin Core.*
|
||||
*/
|
||||
export abstract class BackendProvider {
|
||||
|
||||
invoiceManager: InvoiceManager = null;
|
||||
|
||||
constructor (invoiceManager: InvoiceManager) {
|
||||
this.invoiceManager = invoiceManager;
|
||||
}
|
||||
|
||||
/* Provider information */
|
||||
abstract readonly NAME: string;
|
||||
abstract readonly DESCRIPTION: string;
|
||||
abstract readonly VERSION: string;
|
||||
abstract readonly AUTHOR: string;
|
||||
|
||||
/**
|
||||
* The cryptocurrency that this providers supports.
|
||||
*/
|
||||
abstract readonly CRYPTO: CryptoUnits;
|
||||
|
||||
/**
|
||||
* This function gets called when this provider gets activated.
|
||||
*/
|
||||
abstract onEnable(): void;
|
||||
|
||||
/**
|
||||
* Generate a new address to receive new funds.
|
||||
*/
|
||||
abstract getNewAddress(): Promise<string>;
|
||||
|
||||
/**
|
||||
* Get a transaction from the blockchain.
|
||||
* @param txId Hash of the transcation you're looking for.
|
||||
* @returns See https://developer.bitcoin.org/reference/rpc/gettransaction.html for reference
|
||||
*/
|
||||
abstract getTransaction(txId: string): Promise<ITransaction>;
|
||||
|
||||
/**
|
||||
* Decode a raw transcation that was broadcasted in the network.
|
||||
* @param rawTx Raw transcation
|
||||
* @returns See https://developer.bitcoin.org/reference/rpc/decoderawtransaction.html for reference
|
||||
*/
|
||||
abstract decodeRawTransaction(rawTx: string): Promise<IRawTransaction>;
|
||||
|
||||
/**
|
||||
* Send funds to a specific address.
|
||||
* @param recipient Address of the recipient
|
||||
* @param amount Amount of coins to transfer
|
||||
* @param comment Comment what this transaction is about
|
||||
* @param commentTo Comment on who is receiving it
|
||||
* @param subtractFeeFromAmount The fee will be deducted from the amount being sent
|
||||
* @returns The transcation id
|
||||
*/
|
||||
abstract sendToAddress(
|
||||
recipient: string,
|
||||
amount: number,
|
||||
comment?: string,
|
||||
commentTo?: string,
|
||||
subtractFeeFromAmount?: boolean): Promise<string>;
|
||||
|
||||
/**
|
||||
* Wait for new transactions by the network.
|
||||
*/
|
||||
abstract listener(): void;
|
||||
|
||||
/**
|
||||
* Keep track of unconfirmed transactions.
|
||||
*/
|
||||
abstract watchConfirmations(): void;
|
||||
}
|
||||
|
||||
export interface ITransaction {
|
||||
amount: number;
|
||||
fee: number;
|
||||
confirmations: number;
|
||||
time: number; // Unix timestamp
|
||||
details: {
|
||||
address: string;
|
||||
category: 'send' | 'receive' | 'generate' | 'immature' | 'orphan'
|
||||
vout: number;
|
||||
fee: number;
|
||||
abandoned: boolean
|
||||
}[];
|
||||
hex: string;
|
||||
}
|
||||
|
||||
export interface IRawTransaction {
|
||||
txid: string;
|
||||
hash: string;
|
||||
size: number;
|
||||
vsize: number;
|
||||
weight: number;
|
||||
version: number;
|
||||
vin: {
|
||||
txid: string;
|
||||
vout: number;
|
||||
}[];
|
||||
vout: {
|
||||
value: number;
|
||||
n: number;
|
||||
scriptPubKey: {
|
||||
addresses: string[];
|
||||
}
|
||||
}[];
|
||||
}
|
||||
Reference in New Issue
Block a user