first steps for send coins

This commit is contained in:
einhorn_b 2021-09-29 18:47:10 +02:00 committed by einhornimmond
parent da99d4ee4c
commit 6699b4d6eb
4 changed files with 27 additions and 1 deletions

3
.gitmodules vendored
View File

@ -34,3 +34,6 @@
[submodule "login_server/dependencies/protobuf"]
path = login_server/dependencies/protobuf
url = https://github.com/protocolbuffers/protobuf.git
[submodule "backend/src/proto"]
path = backend/src/proto
url = git@github.com:gradido/gradido_protocol.git

View File

@ -16,6 +16,7 @@
"test": "jest --coverage"
},
"dependencies": {
"@apollo/protobufjs": "^1.2.2",
"@types/jest": "^27.0.2",
"apollo-server-express": "^2.25.2",
"axios": "^0.21.1",
@ -26,6 +27,7 @@
"graphql": "^15.5.1",
"jest": "^27.2.4",
"jsonwebtoken": "^8.5.1",
"libsodium-wrappers": "^0.7.9",
"mysql2": "^2.3.0",
"reflect-metadata": "^0.1.13",
"ts-jest": "^27.0.5",
@ -35,6 +37,7 @@
"devDependencies": {
"@types/express": "^4.17.12",
"@types/jsonwebtoken": "^8.5.2",
"@types/libsodium-wrappers": "^0.7.9",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"eslint": "^7.29.0",

1
backend/src/proto Submodule

@ -0,0 +1 @@
Subproject commit cc9acbb212201a560d86fc87a47665497f11f27d

View File

@ -1,3 +1,8 @@
import { User as dbUser } from '../typeorm/entity/User'
import { Balance as dbBalance } from '../typeorm/entity/Balance'
import { getRepository } from 'typeorm'
import { calculateDecay } from './decay'
function isStringBoolean(value: string): boolean {
const lowerValue = value.toLowerCase()
if (lowerValue === 'true' || lowerValue === 'false') {
@ -6,4 +11,18 @@ function isStringBoolean(value: string): boolean {
return false
}
export { isStringBoolean }
function isHexPublicKey(publicKey:string): boolean {
return /^[0-9A-Fa-f]{64}$/i.test(publicKey)
}
async function hasUserAmount(user:dbUser, amount:number): Promise<boolean> {
if(amount < 0) return false
const balanceRepository = getRepository(dbBalance)
const balance = await balanceRepository.findOne({ userId: user.id })
if(!balance) return false
const decay = await calculateDecay(balance.amount, balance.recordDate, new Date())
return decay > amount
}
export { isHexPublicKey, hasUserAmount, isStringBoolean }