add config-switch and authentication-check before starting

X-Com-sendCoins
This commit is contained in:
Claus-Peter Huebner 2023-09-01 02:25:15 +02:00
parent 47ea0fdb9b
commit a16c1fa991
4 changed files with 27 additions and 2 deletions

View File

@ -19,7 +19,7 @@ const constants = {
LOG_LEVEL: process.env.LOG_LEVEL ?? 'info',
CONFIG_VERSION: {
DEFAULT: 'DEFAULT',
EXPECTED: 'v18.2023-07-10',
EXPECTED: 'v19.2023-09-01',
CURRENT: '',
},
}
@ -124,6 +124,8 @@ if (
const federation = {
FEDERATION_VALIDATE_COMMUNITY_TIMER:
Number(process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER) || 60000,
FEDERATION_XCOM_SENDCOINS_ENABLED:
process.env.FEDERATION_XCOM_SENDCOINS_ENABLED === 'true' || false,
}
export const CONFIG = {

View File

@ -58,6 +58,7 @@ let bob: User
let peter: User
let homeCom: DbCommunity
let foreignCom: DbCommunity
describe('send coins', () => {
beforeAll(async () => {

View File

@ -33,12 +33,13 @@ import { calculateBalance } from '@/util/validate'
import { virtualLinkTransaction, virtualDecayTransaction } from '@/util/virtualTransactions'
import { BalanceResolver } from './BalanceResolver'
import { isHomeCommunity } from './util/communities'
import { isCommunityAuthenticated, isHomeCommunity } from './util/communities'
import { findUserByIdentifier } from './util/findUserByIdentifier'
import { getLastTransaction } from './util/getLastTransaction'
import { getTransactionList } from './util/getTransactionList'
import { sendTransactionsToDltConnector } from './util/sendTransactionsToDltConnector'
import { transactionLinkSummary } from './util/transactionLinkSummary'
import { CONFIG } from '@/config'
export const executeTransaction = async (
amount: Decimal,
@ -484,6 +485,12 @@ export class TransactionResolver {
} else {
// processing a x-community sendCoins
logger.debug('processing a x-community transaction...')
if (!CONFIG.FEDERATION_XCOM_SENDCOINS_ENABLED) {
throw new LogError('X-Community sendCoins disabled per configuration!')
}
if (!(await isCommunityAuthenticated(recipientCommunityIdentifier))) {
throw new LogError('recipient commuity is connected, but still not authenticated yet!')
}
}
return true
}

View File

@ -19,3 +19,18 @@ export async function getCommunityUrl(communityIdentifier: string): Promise<stri
const community = await DbCommunity.findOneByOrFail({ name: communityIdentifier })
return community.url
}
export async function isCommunityAuthenticated(communityIdentifier: string): Promise<boolean> {
const community = await DbCommunity.findOneOrFail({
where: [
{ communityUuid: communityIdentifier },
{ name: communityIdentifier },
{ url: communityIdentifier },
],
})
if (community.authenticatedAt) {
return true
} else {
return false
}
}