Skip to content

Commit

Permalink
Add uploading serialized transaction to syncer
Browse files Browse the repository at this point in the history
This allows the syncer services command to now upload the serialized
transaction format to the API.
  • Loading branch information
NullSoldier committed Dec 24, 2023
1 parent 6090718 commit 959ee9d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/blocks/blocks.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ describe('BlocksController', () => {
mints: [],
burns: [],
},
{
hash: uuid(),
fee: faker.datatype.number(),
size: faker.datatype.number(),
notes: [{ commitment: uuid() }],
spends: [{ nullifier: uuid() }],
mints: [],
burns: [],
serialized: 'serialized',
},
],
},
],
Expand All @@ -169,10 +179,14 @@ describe('BlocksController', () => {
difficulty: block.difficulty,
sequence: block.sequence,
timestamp: block.timestamp.toISOString(),
transactions_count: 1,
transactions_count: 2,
previous_block_hash: block.previous_block_hash,
size: block.size,
});

const serializedBlock = data[0] as SerializedBlockWithTransactions;
expect(serializedBlock.transactions[0].serialized).toBeNull();
expect(serializedBlock.transactions[1].serialized).toBe('serialized');
});
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/transactions/dto/upsert-transactions.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class TransactionDto {
@IsArray()
@ValidateNested({ each: true })
readonly burns!: BurnDto[];

@IsOptional()
@IsString()
readonly serialized?: string;
}

export class UpsertTransactionsDto {
Expand Down
1 change: 1 addition & 0 deletions src/transactions/interfaces/upsert-transaction-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface UpsertTransactionOptions {
size: number;
notes: Note[];
spends: Spend[];
serialized?: string;
}

interface Note {
Expand Down
3 changes: 3 additions & 0 deletions src/transactions/transactions.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ describe('TransactionsController', () => {
spends: [{ nullifier: uuid() }],
mints: [],
burns: [],
serialized: 'serialized'
};

const API_KEY = 'test';
Expand All @@ -431,6 +432,7 @@ describe('TransactionsController', () => {
expect(body1.spends).toStrictEqual(transaction1.spends);
expect(body1.hash).toStrictEqual(transaction1.hash);
expect(body1.expiration).toStrictEqual(transaction1.expiration);
expect(body1.serialized).toBeNull();

const { body: body2 } = await request(app.getHttpServer())
.get('/transactions/find')
Expand All @@ -441,6 +443,7 @@ describe('TransactionsController', () => {
expect(body2.spends).toStrictEqual(transaction2.spends);
expect(body2.hash).toStrictEqual(transaction2.hash);
expect(body2.expiration).toStrictEqual(transaction2.expiration);
expect(body2.serialized).toBe('serialized');
});
});

Expand Down
1 change: 1 addition & 0 deletions src/transactions/transactions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class TransactionsService {
size: tx.size,
notes: classToPlain(tx.notes),
spends: classToPlain(tx.spends),
serialized: tx.serialized ?? null,
})),
skipDuplicates: true,
});
Expand Down

0 comments on commit 959ee9d

Please sign in to comment.