|
|
@ -1,13 +1,12 @@ |
|
|
|
import { AbiItemModel } from '../models/types'; |
|
|
|
import { AbiItemModel } from '../models/types'; |
|
|
|
import { Messenger, RPCMethod, WSProvider } from '@harmony-js/network'; |
|
|
|
import { LogSub } from '@harmony-js/network'; |
|
|
|
import { Contract } from '../contract'; |
|
|
|
import { Contract } from '../contract'; |
|
|
|
import { decode as eventLogDecoder } from '../utils/decoder'; |
|
|
|
import { decode as eventLogDecoder } from '../utils/decoder'; |
|
|
|
import { inputLogFormatter, outputLogFormatter } from '../utils/formatter'; |
|
|
|
import { inputLogFormatter, outputLogFormatter } from '../utils/formatter'; |
|
|
|
export class EventMethod { |
|
|
|
export class EventMethod extends LogSub { |
|
|
|
params: any; |
|
|
|
params: any; |
|
|
|
methodKey: string; |
|
|
|
methodKey: string; |
|
|
|
contract: Contract; |
|
|
|
contract: Contract; |
|
|
|
messenger?: Messenger; |
|
|
|
|
|
|
|
abiItem: AbiItemModel; |
|
|
|
abiItem: AbiItemModel; |
|
|
|
constructor( |
|
|
|
constructor( |
|
|
|
methodKey: string, |
|
|
|
methodKey: string, |
|
|
@ -15,57 +14,18 @@ export class EventMethod { |
|
|
|
abiItem: AbiItemModel, |
|
|
|
abiItem: AbiItemModel, |
|
|
|
contract: Contract, |
|
|
|
contract: Contract, |
|
|
|
) { |
|
|
|
) { |
|
|
|
|
|
|
|
super(inputLogFormatter(params), contract.wallet.messenger); |
|
|
|
this.methodKey = methodKey; |
|
|
|
this.methodKey = methodKey; |
|
|
|
this.contract = contract; |
|
|
|
this.contract = contract; |
|
|
|
this.messenger = contract.wallet.messenger; |
|
|
|
|
|
|
|
this.params = params; |
|
|
|
this.params = params; |
|
|
|
this.abiItem = abiItem; |
|
|
|
this.abiItem = abiItem; |
|
|
|
|
|
|
|
super.subscribe(); |
|
|
|
} |
|
|
|
} |
|
|
|
send() {} |
|
|
|
|
|
|
|
call() {} |
|
|
|
// call() {}
|
|
|
|
estimateGas() {} |
|
|
|
// estimateGas() {}
|
|
|
|
encodeABI() {} |
|
|
|
// encodeABI() {}
|
|
|
|
subscribe(options: any) { |
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
options && |
|
|
|
|
|
|
|
typeof options.filter !== 'undefined' && |
|
|
|
|
|
|
|
typeof options.topics !== 'undefined' |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
throw new Error( |
|
|
|
|
|
|
|
'Invalid subscription options: Only filter or topics are allowed and not both', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.emitter && this.messenger) { |
|
|
|
|
|
|
|
const messenger = this.messenger; |
|
|
|
|
|
|
|
const emitter = this.emitter; |
|
|
|
|
|
|
|
const inputOptions = inputLogFormatter(options); |
|
|
|
|
|
|
|
// 1. getLog
|
|
|
|
|
|
|
|
// 2. subscribe pastlog
|
|
|
|
|
|
|
|
// 3. emit data
|
|
|
|
|
|
|
|
messenger |
|
|
|
|
|
|
|
.send(RPCMethod.GetPastLogs, [inputOptions]) |
|
|
|
|
|
|
|
.then((logs: any) => { |
|
|
|
|
|
|
|
logs.forEach((log: any) => { |
|
|
|
|
|
|
|
const formattedLog = this.onNewSubscriptionItem(log); |
|
|
|
|
|
|
|
emitter.emit('data', formattedLog); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
messenger.subscribe('logs', [inputOptions] || []); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
|
|
emitter.emit('error', error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return this.contract; |
|
|
|
|
|
|
|
// return this.eventSubscriptionFactory
|
|
|
|
|
|
|
|
// .createEventLogSubscription(
|
|
|
|
|
|
|
|
// this.eventLogDecoder,
|
|
|
|
|
|
|
|
// this.contract,
|
|
|
|
|
|
|
|
// this.eventOptionsMapper.map(abiItemModel, this.contract, options),
|
|
|
|
|
|
|
|
// abiItemModel,
|
|
|
|
|
|
|
|
// )
|
|
|
|
|
|
|
|
// .subscribe(callback);
|
|
|
|
|
|
|
|
// this.messenger.subscribe()
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
onNewSubscriptionItem(subscriptionItem: any) { |
|
|
|
onNewSubscriptionItem(subscriptionItem: any) { |
|
|
|
// const log = outputLogFormatter(subscriptionItem);
|
|
|
|
// const log = outputLogFormatter(subscriptionItem);
|
|
|
|
const log = eventLogDecoder( |
|
|
|
const log = eventLogDecoder( |
|
|
@ -80,11 +40,4 @@ export class EventMethod { |
|
|
|
|
|
|
|
|
|
|
|
return log; |
|
|
|
return log; |
|
|
|
} |
|
|
|
} |
|
|
|
get emitter() { |
|
|
|
|
|
|
|
if (this.messenger && this.messenger.provider instanceof WSProvider) { |
|
|
|
|
|
|
|
return this.messenger.provider.emitter; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return undefined; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|