Skip to content

Commit

Permalink
sdk: fix findBalanceProofMatchingBalanceHash$
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevmatos committed Aug 27, 2020
1 parent 1bfa9aa commit 3f1168a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
6 changes: 3 additions & 3 deletions raiden-ts/src/channels/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ export const channelSettleEpic = (
partnerBP$ = findBalanceProofMatchingBalanceHash$(
db,
channel,
Direction.SENT,
Direction.RECEIVED,
partnerBH as Hash,
).pipe(
catchError(() =>
Expand All @@ -1217,13 +1217,13 @@ export const channelSettleEpic = (
.lt(ownBP.transferredAmount.add(ownBP.lockedAmount))
)
return [
[address, ownBP],
[partner, partnerBP],
[address, ownBP],
] as const;
else
return [
[partner, partnerBP],
[address, ownBP],
[partner, partnerBP],
] as const;
}),
mergeMap(([part1, part2]) =>
Expand Down
13 changes: 4 additions & 9 deletions raiden-ts/src/transfers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { concat, hexlify } from 'ethers/utils/bytes';
import { keccak256, randomBytes, bigNumberify, sha256 } from 'ethers/utils';
import { HashZero } from 'ethers/constants';
import { first, mergeMap, map, filter, pluck } from 'rxjs/operators';
import { first, mergeMap, map, filter } from 'rxjs/operators';
import { of, from, defer } from 'rxjs';

import { channelUniqueKey } from '../channels/utils';
Expand All @@ -11,8 +11,7 @@ import { encode } from '../utils/data';
import { Lock, BalanceProofZero } from '../channels/types';
import { Channel } from '../channels';
import { getBalanceProofFromEnvelopeMessage, createBalanceHash } from '../messages';
import { RaidenDatabase } from '../db/types';
import { byPrefix } from '../db/utils';
import { RaidenDatabase, TransferStateish } from '../db/types';
import { TransferState, RaidenTransfer, RaidenTransferStatus, Direction } from './state';

/**
Expand Down Expand Up @@ -185,14 +184,10 @@ export function findBalanceProofMatchingBalanceHash$(
balanceHash: Hash,
) {
if (balanceHash === HashZero) return of(BalanceProofZero);
// TODO: replace allDocs with proper indexes for channel & partner
return defer(() =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
db.allDocs<any>({ include_docs: true, ...byPrefix(`${direction}:`, true) }),
db.find({ selector: { channel: channelUniqueKey(channel), direction } }),
).pipe(
mergeMap((result) => from(result.rows)),
pluck('doc'),
filter((doc): doc is TransferState => doc && doc.channel === channelUniqueKey(channel)),
mergeMap(({ docs }) => from(docs as TransferStateish[])),
mergeMap((doc) => {
const transferState = decode(TransferState, doc);
return from([transferState.transfer, transferState.unlock, transferState.expired]);
Expand Down

0 comments on commit 3f1168a

Please sign in to comment.