Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit fda0067

Browse files
authored
DataUnion types (#209)
Types for getAdminAddress, setAdminFee, executeWithdraw. After these modifications, and PR #207 all public methods of DataUnion are annotated with valid types. Remove deployTxReceipt field which was not used
1 parent d35841c commit fda0067

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/dataunion/Contracts.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCreate2Address, isAddress } from '@ethersproject/address'
22
import { arrayify, hexZeroPad } from '@ethersproject/bytes'
3-
import { Contract } from '@ethersproject/contracts'
3+
import { Contract, ContractReceipt } from '@ethersproject/contracts'
44
import { keccak256 } from '@ethersproject/keccak256'
55
import { defaultAbiCoder } from '@ethersproject/abi'
66
import { verifyMessage } from '@ethersproject/wallet'
@@ -218,14 +218,14 @@ export class Contracts {
218218
return trAMB
219219
}
220220

221-
async payForSignatureTransport(tr: { events: any[] }, options: { pollingIntervalMs?: number, retryTimeoutMs?: number } = {}) {
221+
async payForSignatureTransport(tr: ContractReceipt, options: { pollingIntervalMs?: number, retryTimeoutMs?: number } = {}) {
222222
const {
223223
pollingIntervalMs = 1000,
224224
retryTimeoutMs = 60000,
225225
} = options
226-
log(`Got receipt, filtering UserRequestForSignature from ${tr.events.length} events...`)
226+
log(`Got receipt, filtering UserRequestForSignature from ${tr.events!.length} events...`)
227227
// event UserRequestForSignature(bytes32 indexed messageId, bytes encodedData);
228-
const sigEventArgsArray = tr.events.filter((e: Todo) => e.event === 'UserRequestForSignature').map((e: Todo) => e.args)
228+
const sigEventArgsArray = tr.events!.filter((e: Todo) => e.event === 'UserRequestForSignature').map((e: Todo) => e.args)
229229
if (sigEventArgsArray.length < 1) {
230230
throw new Error("No UserRequestForSignature events emitted from withdraw transaction, can't transport withdraw to mainnet")
231231
}
@@ -309,7 +309,7 @@ export class Contracts {
309309
duName,
310310
ethersOptions
311311
)
312-
const tr = await tx.wait(confirmations)
312+
await tx.wait(confirmations)
313313

314314
log(`Data Union "${duName}" (mainnet: ${duMainnetAddress}, sidechain: ${duSidechainAddress}) deployed to mainnet, waiting for side-chain...`)
315315
await until(
@@ -320,8 +320,6 @@ export class Contracts {
320320

321321
const dataUnion = new Contract(duMainnetAddress, dataUnionMainnetABI, mainnetWallet)
322322
// @ts-expect-error
323-
dataUnion.deployTxReceipt = tr
324-
// @ts-expect-error
325323
dataUnion.sidechain = new Contract(duSidechainAddress, dataUnionSidechainABI, sidechainProvider)
326324
return dataUnion
327325

src/dataunion/DataUnion.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { TransactionReceipt, TransactionResponse } from '@ethersproject/provider
66
import debug from 'debug'
77
import { Contracts } from './Contracts'
88
import StreamrClient from '../StreamrClient'
9-
import { EthereumAddress, Todo } from '../types'
9+
import { EthereumAddress } from '../types'
1010
import { until, getEndpointUrl } from '../utils'
1111
import authFetch from '../rest/authFetch'
1212

@@ -296,7 +296,7 @@ export class DataUnion {
296296
return +adminFeeBN.toString() / 1e18
297297
}
298298

299-
async getAdminAddress(): Promise<Todo> {
299+
async getAdminAddress(): Promise<EthereumAddress> {
300300
const duMainnet = this.getContracts().getMainnetContractReadOnly(this.contractAddress)
301301
return duMainnet.owner()
302302
}
@@ -446,7 +446,7 @@ export class DataUnion {
446446
/**
447447
* Admin: set admin fee (between 0.0 and 1.0) for the data union
448448
*/
449-
async setAdminFee(newFeeFraction: number): Promise<Todo> {
449+
async setAdminFee(newFeeFraction: number): Promise<TransactionReceipt> {
450450
if (newFeeFraction < 0 || newFeeFraction > 1) {
451451
throw new Error('newFeeFraction argument must be a number between 0...1, got: ' + newFeeFraction)
452452
}
@@ -539,7 +539,7 @@ export class DataUnion {
539539
// template for withdraw functions
540540
// client could be replaced with AMB (mainnet and sidechain)
541541
private async _executeWithdraw(
542-
getWithdrawTxFunc: () => Promise<Todo & { events: any[] }>,
542+
getWithdrawTxFunc: () => Promise<TransactionResponse>,
543543
recipientAddress: EthereumAddress,
544544
options: DataUnionWithdrawOptions = {}
545545
): Promise<TransactionReceipt> {

0 commit comments

Comments
 (0)