machinomy
Version:
Micropayments powered by Ethereum
60 lines (59 loc) • 3.04 kB
TypeScript
/// <reference types="@machinomy/types-web3" />
/// <reference types="@machinomy/types-truffle-contract" />
/// <reference types="@types/node" />
import IChannelsDatabase from './storage/IChannelsDatabase';
import PaymentManager from './PaymentManager';
import ChannelContract from './ChannelContract';
import { TransactionResult } from 'truffle-contract';
import Payment from './payment';
import MachinomyOptions from './MachinomyOptions';
import IChannelManager from './IChannelManager';
import * as BigNumber from 'bignumber.js';
import ChannelId from './ChannelId';
import { EventEmitter } from 'events';
import * as Web3 from 'web3';
import IPaymentsDatabase from './storage/IPaymentsDatabase';
import ITokensDatabase from './storage/ITokensDatabase';
import { PaymentChannel } from './PaymentChannel';
import { RemoteChannelInfo } from './RemoteChannelInfo';
export default class ChannelManager extends EventEmitter implements IChannelManager {
/** Default settlement period for a payment channel */
static DEFAULT_SETTLEMENT_PERIOD: number;
private account;
private web3;
private channelsDao;
private paymentsDao;
private tokensDao;
private channelContract;
private paymentManager;
private mutex;
private machinomyOptions;
constructor(account: string, web3: Web3, channelsDao: IChannelsDatabase, paymentsDao: IPaymentsDatabase, tokensDao: ITokensDatabase, channelContract: ChannelContract, paymentManager: PaymentManager, machinomyOptions: MachinomyOptions);
openChannel(sender: string, receiver: string, amount: BigNumber.BigNumber, minDepositAmount?: BigNumber.BigNumber, channelId?: ChannelId | string, tokenContract?: string): Promise<PaymentChannel>;
closeChannel(channelId: string | ChannelId): Promise<TransactionResult>;
deposit(channelId: string, value: BigNumber.BigNumber): Promise<TransactionResult>;
nextPayment(channelId: string | ChannelId, amount: BigNumber.BigNumber, meta: string): Promise<Payment>;
spendChannel(payment: Payment, token?: string): Promise<Payment>;
acceptPayment(payment: Payment): Promise<string>;
requireOpenChannel(sender: string, receiver: string, amount: BigNumber.BigNumber, minDepositAmount?: BigNumber.BigNumber, tokenContract?: string): Promise<PaymentChannel>;
channels(): Promise<PaymentChannel[]>;
openChannels(): Promise<PaymentChannel[]>;
settlingChannels(): Promise<PaymentChannel[]>;
channelById(channelId: ChannelId | string): Promise<PaymentChannel | null>;
verifyToken(token: string): Promise<boolean>;
/**
* DO NOT USE THIS.
* @param sender
* @param receiver
* @param remoteChannels
*/
syncChannels(sender: string, receiver: string, remoteChannels: RemoteChannelInfo[]): Promise<void>;
lastPayment(channelId: string | ChannelId): Promise<Payment | null>;
private internalOpenChannel;
private internalCloseChannel;
private settle;
private claim;
private buildChannel;
private handleUnknownChannel;
private findChannel;
}