/// /// import * as Web3 from 'web3'; import { PaymentChannel } from './PaymentChannel'; import * as BigNumber from 'bignumber.js'; import Payment from './payment'; import { TransactionResult } from 'truffle-contract'; import ChannelId from './ChannelId'; import { AcceptPaymentResponse } from './accept_payment_response'; import { AcceptTokenRequest } from './accept_token_request'; import { AcceptTokenResponse } from './accept_token_response'; import Registry from './Registry'; import MachinomyOptions from './MachinomyOptions'; import BuyOptions from './BuyOptions'; import NextPaymentResult from './NextPaymentResult'; import BuyResult from './BuyResult'; import { PaymentRequiredResponse } from './PaymentRequiredResponse'; /** * Machinomy is a library for micropayments in Ether over HTTP. * Machinomy provides API to send and receive a minuscule amount of money instantly. * Core method is [buy]{@link Machinomy.buy}. The method does all the heavy lifting providing an easy interface * for micropayments. * * See [examples](https://github.com/machinomy/machinomy/tree/master/examples) directory for both client and server sides. * * NB. All monetary values below are denominated in Wei, including: [buy]{@link Machinomy.buy} and * [deposit]{@link Machinomy.deposit} methods. */ export default class Machinomy { readonly registry: Registry; /** Ethereum account address that sends the money. */ private readonly account; private migrated; constructor(account: string, web3: Web3, options?: MachinomyOptions); /** * Entrypoint for a purchasing. * * Wnen you `buy` for the first time from the same receiver, the method opens a channel with a deposit equal to `price`✕10. * Next method call forms a payment and sends it via http to `gateway` url. * * The method then returns a token and channel id, in form of {@link BuyResult}. * * @example *
machinomy.buy({
     *   receiver: receiver, // address
     *   price: 100,
     *   gateway: 'http://localhost:3001/machinomy'
     *  })
     * 
*/ buy(options: BuyOptions): Promise; payment(options: BuyOptions): Promise; pry(uri: string, datetime?: number): Promise; buyUrl(uri: string): Promise; /** * Put more money into the channel. * * @example *

     * let channelId = '0x0bf080aeb3ed7ea6f9174d804bd242f0b31ff1ea24800344abb580cd87f61ca7'
     * machinomy.deposit(channelId, web3.toWei(1, "ether").toNumber(())) // Put 1 Ether more
     * 
* * @param channelId - Channel id. * @param value - Size of deposit in Wei. */ deposit(channelId: string, value: BigNumber.BigNumber | number): Promise; open(receiver: string, value: BigNumber.BigNumber | number, channelId?: ChannelId | string, tokenContract?: string): Promise; /** * Returns the list of opened channels. */ channels(): Promise; openChannels(): Promise; settlingChannels(): Promise; channelById(channelId: string): Promise; /** * Share the money between sender and reciver according to payments made. * * For example a channel was opened with 10 Ether. Sender makes 6 purchases, 1 Ether each. * Total value transferred is 6 Ether. * If a party closes the channel, the money deposited to the channel are split. * The receiver gets 6 Ether. 4 unspent Ethers return to the sender. * * A channel can be closed in two ways, according to what party initiates that. * The method nicely abstracts over that, so you do not need to know what is really going on under the hood. * For more details on how payment channels work refer to a website. */ close(channelId: string): Promise; /** * Save payment into the storage and return an id of the payment. The id can be used by {@link Machinomy.paymentById}. */ acceptPayment(req: any): Promise; /** * Return information about the payment by id. */ paymentById(id: string): Promise; acceptToken(req: AcceptTokenRequest): Promise; shutdown(): Promise; private nextPayment; private checkMigrationsState; }