Skip to content

Commit

Permalink
Merge pull request #344 from AdExNetwork/withdraw-fix
Browse files Browse the repository at this point in the history
withdraw with sweeping bugfix
  • Loading branch information
ivopaunov authored Feb 17, 2020
2 parents 41456f1 + 9d40fb1 commit 460a27b
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions src/services/smart-contracts/actions/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,44 +198,45 @@ export async function getChannelsWithOutstanding({ identityAddr, wallet }) {
const bTree = new BalanceTree(lastApprovedBalances)
return {
lastApprovedSigs,
// mTree,
lastApprovedBalances,
bTree,
channel,
}
})
.filter(({ bTree }) => {
return bTree && !bTree.getBalance(identityAddr).isZero()
})
.map(async ({ channel, lastApprovedSigs, bTree }) => {
// mTree,
const balance = bTree.getBalance(identityAddr).toString()

const outstanding = await getWithdrawnPerUserOutstanding({
AdExCore,
channel,
balance,
identityAddr,
})

const outstandingAvailable = outstanding.sub(
bigNumberify(feeTokenWhitelist[channel.depositAsset].min)
)

const balanceNum = bigNumberify(channel.depositAmount)
.sub(bigNumberify(channel.spec.validators[0].fee || 0))
.sub(bigNumberify(channel.spec.validators[1].fee || 0))

return {
channel,
balance,
lastApprovedSigs,
outstanding,
outstandingAvailable,
// mTree,
bTree,
balanceNum,
.map(
async ({ channel, lastApprovedSigs, lastApprovedBalances, bTree }) => {
// mTree,
const balance = bTree.getBalance(identityAddr).toString()

const outstanding = await getWithdrawnPerUserOutstanding({
AdExCore,
channel,
balance,
identityAddr,
})

const outstandingAvailable = outstanding.sub(
bigNumberify(feeTokenWhitelist[channel.depositAsset].min)
)

const balanceNum = bigNumberify(channel.depositAmount)
.sub(bigNumberify(channel.spec.validators[0].fee || 0))
.sub(bigNumberify(channel.spec.validators[1].fee || 0))

return {
channel,
balance,
lastApprovedSigs,
outstanding,
outstandingAvailable,
lastApprovedBalances,
balanceNum,
}
}
})
)
)

const all = Object.assign(
Expand Down Expand Up @@ -298,11 +299,11 @@ async function getChannelsToSweepFrom({ amountToSweep, withBalance = [] }) {
const getChannelWithdrawData = ({
identityAddr,
balance,
// mTree,
bTree,
lastApprovedBalances,
lastApprovedSigs,
ethChannelTuple,
}) => {
const bTree = new BalanceTree(lastApprovedBalances)
const proof = bTree.getProof(identityAddr)
const vsig1 = splitSig(lastApprovedSigs[0])
const vsig2 = splitSig(lastApprovedSigs[1])
Expand Down Expand Up @@ -380,8 +381,7 @@ export async function getSweepChannelsTxns({ account, amountToSweep }) {

const txns = channelsToSweep.map((c, i) => {
const {
bTree,
// mTree,
lastApprovedBalances,
channel,
lastApprovedSigs,
outstanding,
Expand All @@ -393,8 +393,7 @@ export async function getSweepChannelsTxns({ account, amountToSweep }) {
const data = getChannelWithdrawData({
identityAddr,
balance,
// mTree,
bTree,
lastApprovedBalances,
lastApprovedSigs,
ethChannelTuple,
})
Expand Down

0 comments on commit 460a27b

Please sign in to comment.