diff --git a/src/feeder.ts b/src/feeder.ts index ddef714..9c73a5c 100644 --- a/src/feeder.ts +++ b/src/feeder.ts @@ -28,15 +28,19 @@ if (cluster.isPrimary) { console.log("Feeding the server..."); const data = readFileSync(TESTNET_CSV, 'utf8') const lines = data.split('\n').map(line => { - const [ from, to, weight ] = line.split(' ') - return { from, to, weight } - }).filter(line => line.from !== 'from' && line.from !== ''); + const [ fromStr, toStr, amountStr ] = line.split(' ') + return { + from: parseInt(fromStr), + to: parseInt(toStr), + amount: parseFloat(amountStr) + }; + }).filter(obj => !isNaN(obj.from) && !isNaN(obj.to) && !isNaN(obj.amount)); for (let lineNo = mod; lineNo < lines.length; lineNo += numCPUs) { // console.log(process.pid, mod, lineNo, cumm); let cmd; - if (lines[lineNo].from === '0') { + if (lines[lineNo].from === 0) { cmd = 'DISBURSEMENT'; - } else if (lines[lineNo].to === '0') { + } else if (lines[lineNo].to === 0) { cmd = 'RECLAMATION'; } else { cmd = 'STANDARD'; diff --git a/src/inmem.ts b/src/inmem.ts index 304fa37..a3f482f 100644 --- a/src/inmem.ts +++ b/src/inmem.ts @@ -7,7 +7,7 @@ export class InMemStores { constructor() { this.balances = {}; } - ensureBalance(thisParty: string, otherParty: string): void { + ensureBalance(thisParty: number, otherParty: number): void { if (typeof this.balances[thisParty] === 'undefined') { this.balances[thisParty] = {}; } @@ -21,7 +21,7 @@ export class InMemStores { async disconnect(): Promise { // noop } - async storeTransaction({ thisParty, otherParty, amount }: { thisParty: string, otherParty: string, amount: number }): Promise { + async storeTransaction({ thisParty, otherParty, amount }: { thisParty: number, otherParty: number, amount: number }): Promise { this.ensureBalance(thisParty, otherParty); this.balances[thisParty][otherParty] += amount; return this.balances[thisParty][otherParty]; diff --git a/src/redis.ts b/src/redis.ts index c10bcdc..cdc4af0 100644 --- a/src/redis.ts +++ b/src/redis.ts @@ -14,7 +14,7 @@ export class RedisStores { async disconnect(): Promise { await this.client.quit(); } - async storeTransaction({ thisParty, otherParty, amount }: { thisParty: string, otherParty: string, amount: number }): Promise { + async storeTransaction({ thisParty, otherParty, amount }: { thisParty: number, otherParty: number, amount: number }): Promise { // don't wait for this to finish: this.client.incrByFloat(`${thisParty}:${otherParty}`, amount); // console.log('stored transaction', thisParty, otherParty, amount, newValueString); diff --git a/src/tigerbeetle.ts b/src/tigerbeetle.ts index eb7d7b2..92165a4 100644 --- a/src/tigerbeetle.ts +++ b/src/tigerbeetle.ts @@ -4,7 +4,7 @@ export class TigerBeetleStores { client; constructor() { } - async ensureBalance(thisParty: string, otherParty: string): Promise<{ ledgerId: bigint, thisPartyId: bigint, otherPartyId: bigint}> { + async ensureBalance(thisParty: number, otherParty: number): Promise<{ ledgerId: bigint, thisPartyId: bigint, otherPartyId: bigint}> { // `thisParty` is 1,2,3,... and is multiplied by 1,000,000 to create the ledgerId. // It is multiplied by 1,000,001 to create thisPartyId. // `otherParty` is 0,1,2,3,... (where 0 is the bank for DISBURSEMENT and RECLAMATION) and @@ -13,9 +13,9 @@ export class TigerBeetleStores { // ledgerId: 37,000,000 // thisPartyId: 37,000,037 // otherPartyId: 37,054,235 - const ledgerId = BigInt(parseInt(thisParty)) * BigInt(1000 * 1000); - const thisPartyId = BigInt(parseInt(thisParty)) * BigInt(1000 * 1000 + 1); - const otherPartyId = BigInt(parseInt(otherParty)) * BigInt(1000 * 1000 + 1); + const ledgerId = BigInt(thisParty) * BigInt(1000 * 1000); + const thisPartyId = BigInt(thisParty) * BigInt(1000 * 1000 + 1); + const otherPartyId = BigInt(otherParty) * BigInt(1000 * 1000 + 1); const mainAccount = { id: thisPartyId, @@ -71,7 +71,7 @@ export class TigerBeetleStores { async disconnect(): Promise { // noop } - async storeTransaction({ thisParty, otherParty, amount }: { thisParty: string, otherParty: string, amount: number }): Promise { + async storeTransaction({ thisParty, otherParty, amount }: { thisParty: number, otherParty: number, amount: number }): Promise { const absAmount = Math.abs(amount); const firstChunk = Math.round(absAmount); const afterFirst = 1000 * 1000 * (absAmount - firstChunk);