UNPKG

meta-contract

Version:

Meta Contract SDK

329 lines (328 loc) 10.5 kB
/// <reference types="node" /> import { TxComposer } from '../tx-composer'; import * as mvc from '../mvc'; import { API_NET, Api, API_TARGET } from '..'; import { NftGenesis } from './contract-factory/nftGenesis'; import { Transaction } from '../mvc'; import * as nftProto from './contract-proto/nft.proto'; type SellUtxo = { txId: string; outputIndex: number; sellerAddress: string; price: number; }; export type NftUtxo = { txId: string; outputIndex: number; satoshis?: number; lockingScript?: mvc.Script; satotxInfo?: { txId: string; outputIndex: number; txHex: string; preTxId: string; preOutputIndex: number; preTxHex: string; preTx?: Transaction; txInputsCount?: number; preNftInputIndex?: number; }; nftAddress?: mvc.Address; preNftAddress?: mvc.Address; preLockingScript?: mvc.Script; publicKey?: mvc.PublicKey; inputIndex?: number; }; export declare class NftManager { private dustCalculator; private network; private purse; private feeb; private _api; private debug; private unlockContractCodeHashArray; get api(): Api; get sensibleApi(): Api; constructor({ purse, network, apiTarget, apiHost, feeb, debug, }: { purse: string; network: API_NET; apiTarget: API_TARGET; apiHost?: string; feeb?: number; debug?: boolean; }); /** * Estimate the cost of genesis * The minimum cost required in the case of 10 utxo inputs * @param opreturnData * @param utxoMaxCount Maximum number of MVC UTXOs supported * @returns */ getGenesisEstimateFee({ opreturnData, utxoMaxCount, }: { opreturnData?: any; utxoMaxCount?: number; }): Promise<number>; getIssueEstimateFee({ sensibleId, opreturnData, utxoMaxCount, }: { sensibleId: string; opreturnData?: any; utxoMaxCount?: number; }): Promise<number>; getTransferEstimateFee({ tokenIndex, codehash, genesis, opreturnData, utxoMaxCount, }: { tokenIndex: string; codehash: string; genesis: string; opreturnData?: any; utxoMaxCount?: number; }): Promise<number>; genesis({ version, genesisWif, totalSupply, opreturnData, utxos: utxosInput, changeAddress, noBroadcast, calcFee, }: { version?: number; genesisWif?: string; totalSupply: string; changeAddress?: string | mvc.Address; opreturnData?: any; utxos?: any[]; noBroadcast?: boolean; calcFee?: boolean; }): Promise<{ fee: number; feeb: number; codehash?: undefined; genesis?: undefined; sensibleId?: undefined; tx?: undefined; txid?: undefined; txHex?: undefined; genesisContract?: undefined; broadcastStatus?: undefined; } | { codehash: string; genesis: string; sensibleId: string; tx: mvc.Transaction; txid: string; txHex: string; genesisContract: NftGenesis; broadcastStatus: string; fee?: undefined; feeb?: undefined; }>; private createGenesisTx; issue(options: any): Promise<{ fee: number; txid: () => string; txHex: string; tx: mvc.Transaction; txComposer?: undefined; tokenIndex?: undefined; } | { txComposer: TxComposer; tokenIndex: string; fee?: undefined; txid?: undefined; txHex?: undefined; tx?: undefined; } | { fee: number; feeb: number; txHex?: undefined; txid?: undefined; tx?: undefined; tokenIndex?: undefined; } | { txHex: string; txid: string; tx: mvc.Transaction; tokenIndex: string; fee?: undefined; feeb?: undefined; }>; mint({ version, sensibleId, metaTxId, metaOutputIndex, opreturnData, utxos: utxosInput, receiverAddress, changeAddress, noBroadcast, calcFee, }: { version?: number; sensibleId: string; metaTxId: string; metaOutputIndex: number; opreturnData?: any; utxos?: any[]; receiverAddress?: string | mvc.Address; changeAddress?: string | mvc.Address; noBroadcast?: boolean; calcFee?: boolean; }): Promise<{ fee: number; txid: () => string; txHex: string; tx: mvc.Transaction; txComposer?: undefined; tokenIndex?: undefined; } | { txComposer: TxComposer; tokenIndex: string; fee?: undefined; txid?: undefined; txHex?: undefined; tx?: undefined; } | { fee: number; feeb: number; txHex?: undefined; txid?: undefined; tx?: undefined; tokenIndex?: undefined; } | { txHex: string; txid: string; tx: mvc.Transaction; tokenIndex: string; fee?: undefined; feeb?: undefined; }>; transfer({ genesis, codehash, tokenIndex, senderWif, receiverAddress, opreturnData, utxos: utxosInput, noBroadcast, }: { genesis: string; codehash: string; tokenIndex: string; senderWif: string; receiverAddress: string | mvc.Address; opreturnData?: any; utxos?: any[]; noBroadcast?: boolean; }): Promise<{ txHex: string; txid: string; tx: mvc.Transaction; runtime: number; }>; sell({ genesis, codehash, tokenIndex, sellerWif, price, changeAddress, opreturnData, utxos: utxosInput, noBroadcast, middleChangeAddress, middleWif, }: { genesis: string; codehash: string; tokenIndex: string; sellerWif: string; price: number; changeAddress?: string | mvc.Address; opreturnData?: string[] | string; utxos?: any[]; noBroadcast?: boolean; middleChangeAddress?: string | mvc.Address; middleWif?: string; }): Promise<{ tx: mvc.Transaction; txHex: string; txid: string; sellTxId: string; sellTx: mvc.Transaction; sellTxHex: string; runtime: number; }>; cancelSell({ genesis, codehash, tokenIndex, sellerWif, sellUtxo, opreturnData, utxos: utxosInput, changeAddress, noBroadcast, middleChangeAddress, middlePrivateKey, }: { genesis: string; codehash: string; tokenIndex: string; sellerWif?: string | mvc.PrivateKey; opreturnData?: any; utxos?: any[]; changeAddress?: string | mvc.Address; noBroadcast?: boolean; sellUtxo?: SellUtxo; middleChangeAddress?: string | mvc.Address; middlePrivateKey?: string | mvc.PrivateKey; }): Promise<{ tx: mvc.Transaction; txHex: string; txid: string; unlockCheckTxId: string; unlockCheckTx: mvc.Transaction; unlockCheckTxHex: string; runtime: number; }>; private createCancelSellTx; buy({ genesis, codehash, tokenIndex, buyerWif, buyerAddress, sellUtxo, opreturnData, utxos: utxosInput, changeAddress, noBroadcast, middleChangeAddress, middleWif, publisherAddress, publisherFee, publisherFeeRate, creatorAddress, creatorFee, creatorFeeRate, }: { genesis: string; codehash: string; tokenIndex: string; buyerWif?: string; buyerAddress?: string | mvc.Address; sellUtxo?: SellUtxo; opreturnData?: any; utxos?: any[]; changeAddress?: string | mvc.Address; noBroadcast?: boolean; middleChangeAddress?: string | mvc.Address; middleWif?: string; publisherAddress?: string; publisherFee?: number; publisherFeeRate?: number; creatorAddress?: string; creatorFee?: number; creatorFeeRate?: number; }): Promise<{ tx: mvc.Transaction; txHex: string; txid: string; unlockCheckTxId: string; unlockCheckTx: mvc.Transaction; unlockCheckTxHex: string; runtime: number; }>; private createBuyTx; private createSellTx; private pretreatNftUtxo; private createTransferTx; private createMintTx; private getGenesisHash; private updateGenesisContract; private unlockGenesisAndChange; private unlockNftAndChange; private unlockNftAndChangeFromContract; _calGenesisEstimateFee(totalSupply: any, opreturnData: any, feeb: any): Promise<number>; _calIssueEstimateFee({ genesisUtxoSatoshis, opreturnData, utxoMaxCount, }: { genesisUtxoSatoshis: number; opreturnData?: any; utxoMaxCount?: number; }): Promise<number>; private _calTransferEstimateFee; static parseTokenScript(scriptBuf: Buffer, network?: API_NET): { codehash: string; genesis: string; sensibleId: string; metaidOutpoint: nftProto.MetaidOutpoint; nftAddress: string; totalSupply: any; tokenIndex: any; genesisHash: string; sensibleID: nftProto.SensibleID; protoVersion: number; protoType: number; }; getCancelSellEstimateFee({ genesis, codehash, tokenIndex, sellerWif, sellUtxo, opreturnData, utxoMaxCount, }: { genesis: string; codehash: string; tokenIndex: string; sellerWif: string; sellUtxo?: SellUtxo; opreturnData?: any; utxoMaxCount?: number; }): Promise<number>; getBuyEstimateFee({ genesis, codehash, tokenIndex, buyerWif, sellUtxo, opreturnData, utxoMaxCount, }: { genesis: string; codehash: string; tokenIndex: string; buyerWif: string; sellUtxo?: SellUtxo; opreturnData?: any; utxoMaxCount?: number; }): Promise<number>; getSellEstimateFee({ genesis, codehash, tokenIndex, senderWif, opreturnData, utxoMaxCount, }: { genesis: string; codehash: string; tokenIndex: string; senderWif?: string; senderPrivateKey?: string | mvc.PrivateKey; senderPublicKey?: string | mvc.PublicKey; opreturnData?: any; utxoMaxCount?: number; }): Promise<number>; private _calSellEstimateFee; private _calCancelSellEstimateFee; private _calBuyEstimateFee; private _checkRoyaltyParams; } export {};