Skip to content

Commit

Permalink
wip: remove members from pool endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
L03TJ3 committed Sep 17, 2024
1 parent 97f6f24 commit 59a275f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/server/blockchain/MultiWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class MultiWallet {
async registerRedtent(account: string, countryCode: string, log = multiLogger) {
return Promise.all(this.wallets.map(wallet => wallet.registerRedtent(account, countryCode, log)))
}

async removePoolMember(account: string, poolAddress: string, log = multiLogger) {
return Promise.all(this.wallets.map(wallet => wallet.removePoolMember(account, poolAddress, log)))
}
}

const celoWallet =
Expand Down
31 changes: 31 additions & 0 deletions src/server/blockchain/Web3Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,37 @@ export class Web3Wallet {
}
}

async removePoolMember(account: string, poolAddress: string, customLogger = null): Promise<TransactionReceipt> {
const logger = customLogger || this.log

try {
let encodedCall = this.web3.eth.abi.encodeFunctionCall(
{
name: 'removeMember',
type: 'function',
inputs: [
{
name: 'member',
type: 'address'
}
]
},
[account]
)

const transaction = await this.proxyContract.methods.genericCall(poolAddress, encodedCall, 0)
const tx = await this.sendTransaction(transaction, {}, undefined, false, logger)

logger.info('removePoolMember success', { account, tx: tx.transactionHash, poolAddress })
return tx
} catch (exception) {
const { message } = exception

logger.error('removePoolMember failed', message, exception, { account, poolAddress })
throw exception
}
}

/**
* Helper function to handle a tx Send call
* @param tx
Expand Down
19 changes: 19 additions & 0 deletions src/server/goodid/goodid-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,23 @@ export default function addGoodIDMiddleware(app: Router, utils, storage) {
}
})
)

app.post(
'/goodid/pool/remove',
requestRateLimiter(10, 1),
wrapAsync(async (req, res) => {
const { body, log } = req
const { address, poolAddress } = body

try {
await MultiWallet.removePoolMember(address, poolAddress, log)
res.status(200).json({ success: true })
} catch (exception) {
const { message } = exception

log.error('Failed to remove member from pool:', message, exception, { address, poolAddress })
res.status(400).json({ success: false, error: message })
}
})
)
}

0 comments on commit 59a275f

Please sign in to comment.