diff --git a/servers/mu/src/domain/clients/relay.test.js b/servers/mu/src/domain/clients/relay.test.js index 20512f2ed..9ca9c8b0e 100644 --- a/servers/mu/src/domain/clients/relay.test.js +++ b/servers/mu/src/domain/clients/relay.test.js @@ -32,7 +32,7 @@ describe('topUpWith function', function () { logger.tap = () => (args) => { return args } - const fetchTransactionDetails = async () => { + const fetchTransactions = async () => { return { data: { transactions: { @@ -49,7 +49,7 @@ describe('topUpWith function', function () { } } } - let topUp = topUpWith({ fetch, logger, wallet, address, fetchTransactionDetails }) + let topUp = topUpWith({ fetch, logger, wallet, address, fetchTransactions }) it('should correctly sign and verify a request', async function () { const params = { diff --git a/servers/mu/src/domain/lib/write-message-tx.js b/servers/mu/src/domain/lib/write-message-tx.js index ed1f4325b..b2c08a6e5 100644 --- a/servers/mu/src/domain/lib/write-message-tx.js +++ b/servers/mu/src/domain/lib/write-message-tx.js @@ -43,6 +43,16 @@ export function writeMessageTxWith (env) { if(!amount || !sender) { return Rejected(new Error('Must set Sender and Quantity to top up.', { cause: ctx })) } + + if(!Object.keys(RELAY_MAP).includes("ALLOWED_CURRENCIES")) { + return Rejected(new Error('No allowed currencies configured on this MU.', { cause: ctx })) + } + + if(!RELAY_MAP["ALLOWED_CURRENCIES"].includes("ALL")) { + if(!RELAY_MAP["ALLOWED_CURRENCIES"].includes(ctx.cachedMsg.fromProcessId)) { + return Rejected(new Error('This currency is not supported on this MU.', { cause: ctx })) + } + } return topUp({ctx, relayUrl: RELAY_MAP[ctx.tx.processId].url, amount, recipientProcessId: sender}) .bimap( diff --git a/servers/mu/src/domain/lib/write-message-tx.test.js b/servers/mu/src/domain/lib/write-message-tx.test.js index 3480e144f..55dbfc83a 100644 --- a/servers/mu/src/domain/lib/write-message-tx.test.js +++ b/servers/mu/src/domain/lib/write-message-tx.test.js @@ -96,6 +96,7 @@ describe('writeMessageTxWith', () => { } }, RELAY_MAP: { + 'ALLOWED_CURRENCIES': ["fromid"], 'mappedid1': { 'url': 'url1' }, 'mappedid2': { 'url': 'url1' } }, @@ -115,6 +116,7 @@ describe('writeMessageTxWith', () => { url: 'https://foo.bar' }, cachedMsg: { + fromProcessId: 'fromid', msg: { Tags: [{ name: 'Action', @@ -156,6 +158,7 @@ describe('writeMessageTxWith', () => { } }, RELAY_MAP: { + 'ALLOWED_CURRENCIES': ["ALL"], 'mappedid1': { 'url': 'url1' }, 'mappedid2': { 'url': 'url1' } },