Last active
February 19, 2020 01:09
-
-
Save alexytiger/1a6354892dcef8835cf1a3d629903704 to your computer and use it in GitHub Desktop.
e-book
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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