Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Created September 28, 2019 13:20
Show Gist options
  • Save alexytiger/ddfe583d85130e73aa65c2328d7a024a to your computer and use it in GitHub Desktop.
Save alexytiger/ddfe583d85130e73aa65c2328d7a024a to your computer and use it in GitHub Desktop.
public removePurchaseContract(productKey: string): Observable<string> {
const bytes32Key = utils.formatBytes32String(productKey);
const token = this.contractToken.removeContractByKey(bytes32Key);
return from(token)
.pipe(
switchMap((tx: any) => {
console.log('removeContractByKey Transaction', tx);
// Wait for transaction to be mined
// Returned a Promise which would resolve to the TransactionReceipt once it is mined.
return from(tx.wait()).pipe(
tap((txReceipt: any) => console.log('TransactionReceipt: ', txReceipt)),
// The receipt will have an "events" Array, which will have
// the emitted event from the Contract. The "logRemovePurchaseContract(address sender, bytes32 key))
// call is the last event.
map(txReceipt => txReceipt.events.pop()),
tap(txEvent => console.log('txEvent: ', txEvent)),
map(txEvent => {
// retrieve the key parameter value from the event
const key = txEvent.args['key'];
return utils.parseBytes32String(key as ethers.utils.Arrayish)
}),
)
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment