import { Connector } from '../../connectors/Connector' ; import { Address , Cid , CommPRet , DataCIDSize , DataSize , DataTransferChannel , DealInfo , FileRef , Import , ImportRes , PeerID , QueryOffer , RetrievalEvent , RetrievalOrder , StartDealParams , StorageAsk , StoreID , TransferID , } from '../Types' ; import { WsJsonRpcConnector } from '../../connectors/WsJsonRpcConnector' ; /**
 * The Client methods all have to do with interacting with the storage and retrieval markets as a client.
 */ export class JsonRpcClientMethodGroup { private conn : Connector ; constructor ( conn ) { this . conn = conn ; } param fileRef public async import ( fileRef ) { const result = await this . conn . request ( { method : 'Filecoin.ClientImport' , params : [ fileRef ] , } ) ; return result ; } param importId public async removeImport ( importId ) { const result = await this . conn . request ( { method : 'Filecoin.ClientRemoveImport' , params : [ importId ] , } ) ; return result ; } param dealParams public async startDeal ( dealParams ) { const cid = await this . conn . request ( { method : 'Filecoin.ClientStartDeal' , params : [ dealParams ] , } ) ; return cid ; } param dealCid public async getDealInfo ( dealCid ) { const dealInfo = await this . conn . request ( { method : 'Filecoin.ClientGetDealInfo' , params : [ dealCid ] , } ) ; return dealInfo ; } /**
     * Returns information about the deals made by the local client.
     */ public async listDeals ( ) { const deals = await this . conn . request ( { method : 'Filecoin.ClientListDeals' , params : [ ] , } ) ; return deals ; } public async hasLocal ( cid ) { const hasLocal = await this . conn . request ( { method : 'Filecoin.ClientHasLocal' , params : [ cid ] , } ) ; return hasLocal ; } param cid param pieceCid public async findData ( cid , pieceCid ? ) { const data = await this . conn . request ( { method : 'Filecoin.ClientFindData' , params : [ cid , pieceCid ] , } ) ; return data ; } param miner param root param pieceCid public async minerQueryOffer ( miner , root , pieceCid ? ) { const queryOffer = await this . conn . request ( { method : 'Filecoin.ClientMinerQueryOffer' , params : [ miner , root , pieceCid ] , } ) ; return queryOffer ; } param order param ref public async retrieve ( order , ref ) { await this . conn . request ( { method : 'Filecoin.ClientRetrieve' , params : [ order , ref ] , } ) ; } param peerId param miner public async queryAsk ( peerId , miner ) { const queryAsk = await this . conn . request ( { method : 'Filecoin.ClientQueryAsk' , params : [ peerId , miner ] , } ) ; return queryAsk ; } param path public async calcCommP ( path ) { const commP = await this . conn . request ( { method : 'Filecoin.ClientCalcCommP' , params : [ path ] , } ) ; return commP ; } param ref param outpath public async genCar ( ref , outpath ) { const car = await this . conn . request ( { method : 'Filecoin.ClientGenCar' , params : [ ref , outpath ] , } ) ; return car ; } param root public async dealSize ( root ) { const dataSize = await this . conn . request ( { method : 'Filecoin.ClientDealSize' , params : [ root ] , } ) ; return dataSize ; } /**
     * returns the status of all ongoing transfers of data
     */ public async listDataTransfers ( ) { const transfers = await this . conn . request ( { method : 'Filecoin.ClientListDataTransfers' , params : [ ] , } ) ; return transfers ; } param paymentChannel public async retrieveTryRestartInsufficientFunds ( paymentChannel ) { await this . conn . request ( { method : 'Filecoin.ClientRetrieveTryRestartInsufficientFunds' , params : [ paymentChannel ] , } ) ; } /**
     * lists imported files and their root CIDs
     */ public async listImports ( ) { const imports = await this . conn . request ( { method : 'Filecoin.ClientListImports' , params : [ ] , } ) ; return imports ; } /**
     * returns the status of updated deals
     */ public async getDealUpdates ( cb ) { if ( this . conn instanceof WsJsonRpcConnector ) { const subscriptionId = await this . conn . request ( { method : 'Filecoin.ClientGetDealUpdates' , } ) ; this . conn . on ( subscriptionId , cb ) ; } } param order param ref param cb public async retrieveWithEvents ( order , ref , cb ) { if ( this . conn instanceof WsJsonRpcConnector ) { const subscriptionId = await this . conn . request ( { method : 'Filecoin.ClientRetrieveWithEvents' , } ) ; this . conn . on ( subscriptionId , cb ) ; } } public async dataTransferUpdates ( cb ) { if ( this . conn instanceof WsJsonRpcConnector ) { const subscriptionId = await this . conn . request ( { method : 'Filecoin.ClientDataTransferUpdates' , } ) ; this . conn . on ( subscriptionId , cb ) ; } } param code public async getDealStatus ( code ) { const status = await this . conn . request ( { method : 'Filecoin.ClientGetDealStatus' , params : [ code ] , } ) ; return status ; } param transferId param otherPeer param isInitiator public async restartDataTransfer ( transferId , otherPeer , isInitiator ) { await this . conn . request ( { method : 'Filecoin.ClientRestartDataTransfer' , params : [ transferId , otherPeer , isInitiator ] , } ) ; } param transferId param otherPeer param isInitiator public async cancelDataTransfer ( transferId , otherPeer , isInitiator ) { await this . conn . request ( { method : 'Filecoin.ClientCancelDataTransfer' , params : [ transferId , otherPeer , isInitiator ] , } ) ; } public async dealPieceCID ( rootCid ) { const dataCIDSize = await this . conn . request ( { method : 'Filecoin.ClientDealPieceCID' , params : [ rootCid ] , } ) ; return dataCIDSize ; } }