removed not used zig/c stuff, fix problem with gradido node runtime path

This commit is contained in:
einhornimmond 2026-02-26 11:06:13 +01:00
parent f54463b2bf
commit 81d6f6dbf5
17 changed files with 6 additions and 601 deletions

View File

@ -1,8 +0,0 @@
optimize = "ReleaseSmall"
[modules."lib/hello.zigar"]
source = "zig/hello.zig"
[[targets]]
arch = "x64"
platform = "linux"

View File

@ -1,23 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_COMPACT_ACCOUNT_BALANCE_H
#define __GRADIDO_BLOCKCHAIN_C_COMPACT_ACCOUNT_BALANCE_H
#include <stdint.h>
#include "grdc_public_key_index.h"
#include "../grdl/grdl_unit.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct grdc_account_balance
{
grdl_unit balance;
grdc_public_key_index publicKeyIndex;
} grdc_account_balance;
#ifdef __cplusplus
}
#endif
#endif // __GRADIDO_BLOCKCHAIN_C_COMPACT_ACCOUNT_BALANCE_H

View File

@ -1,104 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_COMPACT_CONFIRMED_TRANSACTION_COMPACT_H
#define __GRADIDO_BLOCKCHAIN_C_COMPACT_CONFIRMED_TRANSACTION_COMPACT_H
#include <stdint.h>
#include "grdc_account_balance.h"
#include "grdc_public_key_index.h"
#include "grdc_tx_id.h"
#include "grdc_tx_timestamps.h"
#include "../grdd/grdd_address_type.h"
#include "../grdd/grdd_balance_derivation_type.h"
#include "../grdd/grdd_cross_group_type.h"
#include "../grdd/grdd_transaction_type.h"
#include "../grdl/grdl_unit.h"
#ifdef __cplusplus
extern "C" {
#endif
// Gradido Compact Confirmed Transaction
struct grdc_confirmed_tx
{
grdc_tx_timestamps timestamps;
// inline Timestamp getConfirmedAt() const { return timestamps.getConfirmedAt(); }
// inline Timestamp getCreatedAt() const { return timestamps.getCreatedAt(); }
// txId and pairingTxId packed to save 8 Bytes padding
uint64_t txNrs[2];
uint32_t communityIdIndex[2];
// inline TxId getTxId() const { return TxId(txNrs[0], communityIdIndex[0]); }
// for cross group transactions, else empty
// inline TxId getPairingTxId() const { return TxId(txNrs[1], communityIdIndex[1]); }
// account balances and memos via txId in separate list/manager/thingy
// enums, usually uint8_t
uint8_t crossGroupType; // grdd_cross_group_type
uint8_t transactionType; // grdd_transaction_type
uint8_t balanceDerivationType; // grdd_balance_derivation_type
uint8_t accountBalanceCount;
grdc_account_balance accountBalances[2];
// common fields for most transactions
union { // 24 Bytes
struct {
grdl_unit amount; // 8 Bytes
grdc_public_key_index recipientPublicKeyIndex; // 8 Bytes
uint64_t targetDate; // 8 Bytes
} creation;
struct {
grdl_unit amount; // 8 Bytes
grdc_public_key_index senderPublicKeyIndex; // 8 Bytes
grdc_public_key_index recipientPublicKeyIndex; // 8 Bytes
} transfer; // also used for redeem deferred transfer, and deferredTransferTransactionNr is stored in extra dictionary
struct {
grdl_unit amount; // 8 Bytes
// work only on local, take communityIdIndex from txId
uint32_t senderPublicKeyIndex; // 4 Bytes
uint32_t recipientPublicKeyIndex; // 4 Bytes
uint32_t timeoutDuration; // 4 Bytes
} deferredTransfer; // fund deferred transfer address only on your own community
struct {
grdc_tx_id deferredTransferTransactionNr; // 16 Bytes, contain 4 Bytes padding
} timeoutDeferredTransfer;
struct {
uint8_t addressType; // grdd_address_type // 1 Byte
uint16_t derivationIndex; // 2 Byte (for the time beeing, update if more than 65535 are needed)
uint32_t nameHashIndex; // 4 Bytes
grdc_public_key_index userPublicKeyIndex; // 8 Bytes
grdc_public_key_index accountPublicKeyIndex; // 8 Bytes
} registerAddress;
struct {
grdc_public_key_index communityPublicKeyIndex; // 8 Bytes
grdc_public_key_index communityAufPublicKeyIndex; // 8 Bytes
grdc_public_key_index communityGmwPublicKeyIndex; // 8 Bytes
} communityRoot;
};
};
inline grdd_timestamp grdc_confirmed_tx_get_confirmed_at(const grdc_confirmed_tx* c) {
return grdc_tx_timestamps_get_confirmed_at(&c->timestamps);
}
inline grdd_timestamp grdc_confirmed_tx_get_created_at(const grdc_confirmed_tx* c) {
return grdc_tx_timestamps_get_created_at(&c->timestamps);
}
inline grdc_tx_id grdc_confirmed_tx_get_tx_id(const grdc_confirmed_tx* c) {
grdc_tx_id txId{.nr = c->txNrs[0], .communityIdIndex = c->communityIdIndex[0]};
return txId;
}
inline grdc_tx_id grdc_confirmed_tx_get_pairing_tx_id(const grdc_confirmed_tx* c) {
grdc_tx_id pairingTxId{.nr = c->txNrs[1], .communityIdIndex = c->communityIdIndex[1]};
return pairingTxId;
}
#ifdef __cplusplus
}
#endif
#endif //__GRADIDO_BLOCKCHAIN_C_COMPACT_CONFIRMED_TRANSACTION_COMPACT_H

View File

@ -1,21 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_COMPACT_PUBLIC_KEY_INDEX_H
#define __GRADIDO_BLOCKCHAIN_C_COMPACT_PUBLIC_KEY_INDEX_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct grdc_public_key_index
{
uint32_t publicKeyIndex;
uint32_t communityIdIndex;
} grdc_public_key_index;
#ifdef __cplusplus
}
#endif
#endif // __GRADIDO_BLOCKCHAIN_C_COMPACT_PUBLIC_KEY_INDEX_H

View File

@ -1,25 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_COMPACT_TRANSACTION_ID
#define __GRADIDO_BLOCKCHAIN_C_COMPACT_TRANSACTION_ID
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct grdc_tx_id
{
uint64_t nr;
uint32_t communityIdIndex;
} grdc_tx_id;
inline bool grdc_tx_id_empty(const grdc_tx_id* id) {
return !id->nr && !id->communityIdIndex;
}
#ifdef __cplusplus
}
#endif
#endif // __GRADIDO_BLOCKCHAIN_C_COMPACT_TRANSACTION_ID

View File

@ -1,42 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_COMPACT_TRANSACTION_TIMESTAMPS_H
#define __GRADIDO_BLOCKCHAIN_C_COMPACT_TRANSACTION_TIMESTAMPS_H
#include <stdint.h>
#include "../grdd/grdd_timestamp.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct grdc_tx_timestamps
{
uint64_t confirmedSeconds;
uint32_t confirmedNanos;
int32_t deltaMs; // add to confirmed second and nanos to get created_at
} grdc_tx_timestamps;
inline grdd_timestamp grdc_tx_timestamps_get_confirmed_at(const grdc_tx_timestamps* in) {
grdd_timestamp t;
t.seconds = in->confirmedSeconds;
t.nanos = in->confirmedNanos;
return t;
}
inline grdd_timestamp grdc_tx_timestamps_get_created_at(const grdc_tx_timestamps* in) {
grdd_timestamp t;
uint64_t sec = (in->confirmedSeconds + in->deltaMs) / 1000;
uint32_t ns = (in->confirmedNanos + (in->deltaMs % 1000)) * 1000000;
if (ns >= 1000000000) {
sec += 1;
ns -= 1000000000;
}
t.seconds = sec;
t.nanos = ns;
return t;
}
#ifdef __cplusplus
}
#endif
#endif //__GRADIDO_BLOCKCHAIN_C_COMPACT_TRANSACTION_TIMESTAMPS_H

View File

@ -1,23 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_DATA_ADDRESS_TYPE_H
#define __GRADIDO_BLOCKCHAIN_C_DATA_ADDRESS_TYPE_H
#ifdef __cplusplus
extern "C" {
#endif
enum grdd_address_type {
GRDD_ADDRESS_TYPE_NONE = 0, // if no address was found
GRDD_ADDRESS_TYPE_COMMUNITY_HUMAN = 1, // creation account for human
GRDD_ADDRESS_TYPE_COMMUNITY_GMW = 2, // community public budget account
GRDD_ADDRESS_TYPE_COMMUNITY_AUF = 3, // community compensation and environment founds account
GRDD_ADDRESS_TYPE_COMMUNITY_PROJECT = 4, // no creations allowed
GRDD_ADDRESS_TYPE_SUBACCOUNT = 5, // no creations allowed
GRDD_ADDRESS_TYPE_CRYPTO_ACCOUNT = 6, // user control his keys, no creations
GRDD_ADDRESS_TYPE_DEFERRED_TRANSFER = 7 // special type, no need for register address
};
#ifdef __cplusplus
}
#endif
#endif //__GRADIDO_BLOCKCHAIN_C_DATA_ADDRESS_TYPE_H

View File

@ -1,26 +0,0 @@
#ifndef GRADIDO_BLOCKCHAIN_C_DATA_BALANCE_DERIVATION_TYPE_H
#define GRADIDO_BLOCKCHAIN_C_DATA_BALANCE_DERIVATION_TYPE_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @enum grdd_balance_derivation_type
*
* Flag to decide if Node calculates balance and decay
* or trusts external data.
*/
enum grdd_balance_derivation_type {
GRDD_BALANCE_DERIVATION_UNSPECIFIED = 0,
/* Balances & decay can be recalculated deterministically */
GRDD_BALANCE_DERIVATION_NODE = 1,
/* Balances are accepted as-is from external / legacy system */
GRDD_BALANCE_DERIVATION_EXTERN = 2
};
#ifdef __cplusplus
}
#endif
#endif /* GRADIDO_BLOCKCHAIN_C_DATA_BALANCE_DERIVATION_TYPE_H */

View File

@ -1,20 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_DATA_CROSS_GROUP_TYPE_H
#define __GRADIDO_BLOCKCHAIN_C_DATA_CROSS_GROUP_TYPE_H
#ifdef __cplusplus
extern "C" {
#endif
enum grdd_cross_group_type
{
GRDD_CROSS_GROUP_TYPE_LOCAL = 0,
GRDD_CROSS_GROUP_TYPE_INBOUND = 1,
GRDD_CROSS_GROUP_TYPE_OUTBOUND = 2,
GRDD_CROSS_GROUP_TYPE_CROSS = 3
};
#ifdef __cplusplus
}
#endif
#endif // __GRADIDO_BLOCKCHAIN_C_DATA_CROSS_GROUP_TYPE_H

View File

@ -1,38 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_DATA_TIMESTAMP_H
#define __GRADIDO_BLOCKCHAIN_C_DATA_TIMESTAMP_H
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct grdd_timestamp
{
int64_t seconds;
int32_t nanos;
} grdd_timestamp;
inline bool grdd_timestamp_empty(const grdd_timestamp* timestamp) {
return !timestamp->seconds && !timestamp->nanos;
}
inline bool grdd_timestamp_eq(const grdd_timestamp* t1, grdd_timestamp* t2) {
return t1->seconds == t2->seconds && t1->nanos == t2->nanos;
}
inline bool grdd_timestamp_gt(const grdd_timestamp* t1, const grdd_timestamp* t2) {
return t1->seconds > t2->seconds || t1->seconds == t2->seconds && t1->nanos > t2->nanos;
}
inline bool grdd_timestamp_lt(const grdd_timestamp* t1, const grdd_timestamp* t2) {
return t1->seconds < t2->seconds || t1->seconds == t2->seconds && t1->nanos < t2->nanos;
}
inline grdd_timestamp grdd_timestamp_sub(const grdd_timestamp* t1, grdd_timestamp* t2) {
grdd_timestamp result{.seconds = t1->seconds - t2->seconds, .nanos = t1->nanos - t2->nanos};
return result;
}
#ifdef __cplusplus
}
#endif
#endif // __GRADIDO_BLOCKCHAIN_C_DATA_TIMESTAMP_H

View File

@ -1,56 +0,0 @@
#ifndef GRADIDO_BLOCKCHAIN_C_DATA_TRANSACTION_TYPE_H
#define GRADIDO_BLOCKCHAIN_C_DATA_TRANSACTION_TYPE_H
#ifdef __cplusplus
extern "C" {
#endif
/*!
* \addtogroup enums
* @{
*/
/*!
* \enum grdd_transaction_type
* Enum for different transaction types
* !!! don't change order
*/
enum grdd_transaction_type {
//! Invalid or Empty Transaction
GRDD_TRANSACTION_TYPE_NONE = 0,
//! Creation Transaction, creates new Gradidos
GRDD_TRANSACTION_TYPE_CREATION,
//! Transfer Transaction, move Gradidos from one account to another
GRDD_TRANSACTION_TYPE_TRANSFER,
//! Group Friends Update Transaction, update relationship between groups
GRDD_TRANSACTION_TYPE_COMMUNITY_FRIENDS_UPDATE,
//! Register new address or sub address to group or move address to another group
GRDD_TRANSACTION_TYPE_REGISTER_ADDRESS,
//! Special Transfer Transaction with timeout used for Gradido Link
GRDD_TRANSACTION_TYPE_DEFERRED_TRANSFER,
//! First Transaction in Blockchain
GRDD_TRANSACTION_TYPE_COMMUNITY_ROOT,
//! Redeeming deferred transfer
GRDD_TRANSACTION_TYPE_REDEEM_DEFERRED_TRANSFER,
//! Timeout deferred transfer, send back locked gdds
GRDD_TRANSACTION_TYPE_TIMEOUT_DEFERRED_TRANSFER,
//! Technical type for using it in for loops, as max index
GRDD_TRANSACTION_TYPE_MAX_VALUE
};
/*! @} */
#ifdef __cplusplus
}
#endif
#endif /* GRADIDO_BLOCKCHAIN_C_DATA_TRANSACTION_TYPE_H */

View File

@ -1,123 +0,0 @@
#include "grdl_unit.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
const double SECONDS_PER_YEAR = 31556952.0; // seconds in a year in gregorian calender
const grdd_timestamp DECAY_START_TIME = (grdd_timestamp){.seconds = 1620927991, .nanos = 0};
double roundToPrecision(double gdd, uint8_t precision)
{
double factor = pow(10.0, precision);
return round(gdd * factor) / factor;
}
grdl_unit grdl_unit_from_decimal(double gdd)
{
grdl_unit gradidoUnit = {
(int64_t)(roundToPrecision(gdd, 4) * 10000.0)
};
return gradidoUnit;
}
grdl_unit grdl_unit_from_string(const char* gdd_string)
{
if (!gdd_string) return (grdl_unit){0};
char* end;
double gdd_double = strtod(gdd_string, &end);
if (end == gdd_string || *end != '\0') {
// invalid string
return (grdl_unit){0};
}
return grdl_unit_from_decimal(gdd_double);
}
int grdl_unit_to_string(const grdl_unit* u, char* buffer, size_t bufferSize, uint8_t precision)
{
if (precision > 4) return 1; // C hat keine Exceptions
// Convert to double
double decimal = (double)(u->gradidoCent) / 10000.0;
// Round down like Node.js if precision < 4
if (precision < 4) {
double factor = pow(10.0, precision);
decimal = round(decimal * factor) / factor;
}
// Write to buffer
int written = snprintf(buffer, bufferSize, "%.*f", precision, decimal);
// snprintf returns number of chars that would have been written (excluding null)
// snprintf return negative value on encoding error
if (written < 0) return 2;
if ((size_t)written < bufferSize) {
return 0;
}
return bufferSize - written;
}
grdl_unit grdl_unit_calculate_decay(const grdl_unit* u, int64_t seconds)
{
if (seconds == 0) return (grdl_unit){u->gradidoCent};
// decay for one year is 50%
/*
* while (seconds >= SECONDS_PER_YEAR) {
mGradidoCent *= 0.5;
seconds -= SECONDS_PER_YEAR;
}
*/
int64_t gradidoCent = u->gradidoCent;
// optimize version from above
if (seconds >= SECONDS_PER_YEAR) {
uint64_t times = (uint64_t)(seconds / SECONDS_PER_YEAR);
seconds = seconds - times * SECONDS_PER_YEAR;
gradidoCent = u->gradidoCent >> times;
if (!seconds) return (grdl_unit){gradidoCent};
}
// */
/*!
* calculate decay factor with compound interest formula converted to q <br>
* n = (lg Kn - lg K0) / lg q => <br>
* lg q = (lg Kn - lg K0) / n => <br>
* q = e^((lg Kn - lg K0) / n) <br>
* <br>
* with:
* <ul>
* <li>q = decay_factor</li>
* <li>n = days_per_year * 60 * 60 * 24 = seconds per year</li>
* <li>Kn = 50 (capital after a year)</li>
* <li>K0 = 100 (capital at start)</li>
* </ul>
* further simplified:
* lg 50 - lg 100 = lg 2 =>
* q = e^(lg 2 / n) = 2^(x/n)
* with x as seconds in which decay occured
*/
// https://www.wolframalpha.com/input?i=%28e%5E%28lg%282%29+%2F+31556952%29%29%5Ex&assumption=%7B%22FunClash%22%2C+%22lg%22%7D+-%3E+%7B%22Log%22%7D
// from wolframalpha, based on the interest rate formula
return (grdl_unit){((int64_t)((double)(gradidoCent) * pow(2.0, (double)((double)(-seconds) / SECONDS_PER_YEAR))))};
}
bool grdl_unit_calculate_duration_seconds(
const grdd_timestamp* startTime,
const grdd_timestamp* endTime,
int64_t* outSeconds
) {
if (!outSeconds) {
return false;
}
if(grdd_timestamp_gt(startTime, endTime) {
return false;
}
grdd_timestamp start = grdd_timestamp_gt(startTime, &DECAY_START_TIME) ? *startTime : DECAY_START_TIME;
grdd_timestamp end = grdd_timestamp_gt(endTime, &DECAY_START_TIME) ? *endTime : DECAY_START_TIME;
if (grdd_timestamp_eq(&start, &end)) {
*outSeconds = 0;
return true;
}
*outSeconds = grdd_timestamp_sub(&end, &start).seconds;
return true;
}

View File

@ -1,84 +0,0 @@
#ifndef __GRADIDO_BLOCKCHAIN_C_LOGIC_UNIT_H
#define __GRADIDO_BLOCKCHAIN_C_LOGIC_UNIT_H
#include "../grdd/grdd_timestamp.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct grdl_unit
{
int64_t gradidoCent;
} grdl_unit;
grdl_unit grdl_unit_from_decimal(double gdd);
grdl_unit grdl_unit_from_string(const char* gdd_string);
//! \return 0 for ok, 1 for invalid precision, 2 for printf encoding error
// and -x if string buffer wasn't big enough where x is the number of missing bytes
int grdl_unit_to_string(const grdl_unit* u, char* buffer, size_t bufferSize, uint8_t precision);
inline grdl_unit grdl_unit_negated(const grdl_unit* u)
{
grdl_unit gradidoUnit = {u->gradidoCent};
gradidoUnit.gradidoCent *= -1;
return gradidoUnit;
}
inline void grdl_unit_negate(grdl_unit* u)
{
if (u) u->gradidoCent = -u->gradidoCent;
}
static inline grdl_unit grdl_unit_zero()
{
return (grdl_unit){0};
}
//! return false if startTime > endTime
bool grdl_unit_calculate_duration_seconds(
const grdd_timestamp* startTime,
const grdd_timestamp* endTime,
int64_t* outSeconds
);
grdl_unit grdl_unit_calculate_decay(const grdl_unit* u, int64_t seconds);
inline grdl_unit grdl_unit_calculate_decay_timestamp(
const grdl_unit* u,
const grdd_timestamp* startTime,
const grdd_timestamp* endTime
) {
int64_t seconds = 0;
if(!grdl_unit_calculate_duration_seconds(startTime, endTime, &seconds)) {
return (grdl_unit){0};
}
return grdl_unit_calculate_decay(u, seconds);
}
inline grdl_unit grld_unit_calculate_compound_interest(const grdl_unit* u, int64_t seconds) {
return grdl_unit_calculate_decay(u, -seconds);
}
inline grdl_unit grld_unit_calculate_compound_interest_timestamp(
const grdl_unit* u,
const grdd_timestamp* startTime,
const grdd_timestamp* endTime
) {
int64_t seconds = 0;
if(!grdl_unit_calculate_duration_seconds(startTime, endTime, &seconds)) {
return (grdl_unit){0};
}
return grdl_unit_calculate_decay(u, -seconds);
}
#ifdef __cplusplus
}
#endif
#endif // __GRADIDO_BLOCKCHAIN_C_LOGIC_UNIT_H

View File

@ -74,6 +74,8 @@ async function ensureGradidoNodeRuntimeAvailable(runtimeFileName: string): Promi
fs.writeFileSync(archivePath, Buffer.from(compressedBuffer))
execSync(`tar -xzf ${archivePath}`, { cwd: runtimeFolder })
}
} else {
console.log('file exist')
}
}

View File

@ -48,7 +48,7 @@ export class GradidoNodeProcess {
const isWindows = process.platform === 'win32'
const binaryName = isWindows ? 'GradidoNode.exe' : 'GradidoNode'
return path.join(__dirname, '..', '..', 'gradido_node', 'bin', binaryName)
return path.join(__dirname, CONFIG.DLT_GRADIDO_NODE_SERVER_HOME_FOLDER, 'bin', binaryName)
}
public start() {
@ -56,10 +56,10 @@ export class GradidoNodeProcess {
this.logger.warn('GradidoNodeProcess already running.')
return
}
this.logger.info(`starting GradidoNodeProcess with path: ${GRADIDO_NODE_RUNTIME_PATH}`)
this.logger.info(`starting GradidoNodeProcess with path: ${GradidoNodeProcess.getRuntimePathFileName()}`)
this.lastStarted = new Date()
const logger = this.logger
this.proc = spawn([GRADIDO_NODE_RUNTIME_PATH], {
this.proc = spawn([GradidoNodeProcess.getRuntimePathFileName()], {
env: {
CLIENTS_HIERO_NETWORKTYPE: CONFIG.HIERO_HEDERA_NETWORK,
SERVER_JSON_RPC_PORT: CONFIG.DLT_NODE_SERVER_PORT.toString(),

View File

@ -6,6 +6,7 @@ const logger = getLogger(`${LOG4JS_BASE_CATEGORY}.utils.filesystem`)
export function checkFileExist(filePath: string): boolean {
try {
console.log(`check access to ${filePath}`)
fs.accessSync(filePath, fs.constants.R_OK | fs.constants.W_OK)
return true
} catch (_err) {

View File

@ -1,5 +0,0 @@
const std = @import("std");
pub fn hello() void {
std.debug.print("Hello world!", .{});
}