Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRI - 811 Add workflowId and workstepId to transaction #820

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:

- Added the required column `workflowId` to the `Transaction` table without a default value. This is not possible if the table is not empty.
- Added the required column `workstepId` to the `Transaction` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "Transaction" ADD COLUMN "workflowId" TEXT NOT NULL,
ADD COLUMN "workstepId" TEXT NOT NULL,
ALTER COLUMN "workflowInstanceId" DROP NOT NULL,
ALTER COLUMN "workstepInstanceId" DROP NOT NULL;
6 changes: 4 additions & 2 deletions examples/bri-3/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ model Workgroup {
model Transaction {
id String @id
nonce Int
workflowInstanceId String
workstepInstanceId String
workflowId String
workflowInstanceId String?
workstepId String
workstepInstanceId String?
fromBpiSubjectAccountId String
fromBpiSubjectAccount BpiSubjectAccount @relation(fields: [fromBpiSubjectAccountId], references: [id], name: "fromBpiSubjectAccount_fk")
toBpiSubjectAccountId String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export class TransactionStorageAgent {
data: {
id: transaction.id,
nonce: transaction.nonce,
workflowInstanceId: transaction.workflowInstanceId,
workstepInstanceId: transaction.workstepInstanceId,
workflowId: transaction.workflowId,
workstepId: transaction.workstepId,
fromBpiSubjectAccountId: transaction.fromBpiSubjectAccountId,
toBpiSubjectAccountId: transaction.toBpiSubjectAccountId,
payload: transaction.payload,
Expand Down
22 changes: 16 additions & 6 deletions examples/bri-3/src/bri/transactions/agents/transactions.agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '../api/err.messages';
import { TransactionResult } from '../models/transactionResult';
import { TransactionStorageAgent } from './transactionStorage.agent';
import { v4 } from 'uuid';

@Injectable()
export class TransactionAgent {
Expand Down Expand Up @@ -53,8 +54,8 @@ export class TransactionAgent {
public createNewTransaction(
id: string,
nonce: number,
workflowInstanceId: string,
workstepInstanceId: string,
workflowId: string,
workstepId: string,
fromBpiSubjectAccount: BpiSubjectAccount,
toBpiSubjectAccount: BpiSubjectAccount,
payload: string,
Expand All @@ -63,8 +64,8 @@ export class TransactionAgent {
return new Transaction(
id,
nonce,
workflowInstanceId,
workstepInstanceId,
workflowId,
workstepId,
fromBpiSubjectAccount,
toBpiSubjectAccount,
payload,
Expand Down Expand Up @@ -131,15 +132,15 @@ export class TransactionAgent {
): Promise<boolean> {
// TODO: Log each validation err for now
const workflow = await this.workflowStorageAgent.getWorkflowById(
tx.workflowInstanceId,
tx.workflowId,
);

if (!workflow) {
return false;
}

const workstep = await this.workstepStorageAgent.getWorkstepById(
tx.workstepInstanceId,
tx.workstepId,
);

if (!workstep) {
Expand Down Expand Up @@ -184,6 +185,15 @@ export class TransactionAgent {
): Promise<TransactionResult> {
const txResult = new TransactionResult();

//Generate and store workflowInstanceId & workstepInstanceId
const workflowInstanceId = v4();
const workstepInstanceId = v4();

tx.updateWorkflowInstanceId(workflowInstanceId);
tx.updateWorkstepInstanceId(workstepInstanceId);

this.txStorageAgent.updateTransaction(tx);

txResult.merkelizedPayload = this.merkleTreeService.merkelizePayload(
JSON.parse(tx.payload),
`${process.env.MERKLE_TREE_HASH_ALGH}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ describe('CreateTransactionDto', () => {
// Arrange
const dto = {
nonce: 123,
workflowInstanceId: '123',
workstepInstanceId: '123',
workflowId: '123',
workstepId: '123',
fromSubjectAccountId: '123',
toSubjectAccountId: '123',
payload: '123',
Expand All @@ -33,8 +33,8 @@ describe('CreateTransactionDto', () => {
const dto = {
id: '123',
nonce: 123,
workflowInstanceId: '123',
workstepInstanceId: '123',
workflowId: '123',
workstepId: '123',
fromSubjectAccountId: '123',
toSubjectAccountId: '123',
payload: '123',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export class CreateTransactionDto {
nonce: number;

@IsNotEmpty()
workflowInstanceId: string;
workflowId: string;

@IsNotEmpty()
workstepInstanceId: string;
workstepId: string;

@IsNotEmpty()
fromSubjectAccountId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ export class TransactionDto {
@AutoMap()
nonce: number;

@AutoMap()
workflowId: string;

@AutoMap()
workflowInstanceId: string;

@AutoMap()
workstepId: string;

@AutoMap()
workstepInstanceId: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ describe('TransactionController', () => {
const requestDto = {
id: uuid(),
nonce: 1,
workflowInstanceId: '42',
workstepInstanceId: '24',
workflowId: '42',
workstepId: '24',
fromSubjectAccountId: fromBpiSubjectAccount.id,
toSubjectAccountId: toBpiSubjectAccount.id,
payload: 'payload1',
Expand All @@ -221,8 +221,8 @@ describe('TransactionController', () => {
const expectedTransaction = new Transaction(
requestDto.id,
requestDto.nonce,
requestDto.workflowInstanceId,
requestDto.workstepInstanceId,
requestDto.workflowId,
requestDto.workstepId,
fromBpiSubjectAccount,
toBpiSubjectAccount,
requestDto.payload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class TransactionController {
new CreateTransactionCommand(
requestDto.id,
requestDto.nonce,
requestDto.workflowInstanceId,
requestDto.workstepInstanceId,
requestDto.workflowId,
requestDto.workstepId,
requestDto.fromSubjectAccountId,
requestDto.toSubjectAccountId,
requestDto.payload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export class CreateTransactionCommand {
constructor(
public readonly id: string,
public readonly nonce: number,
public readonly workflowInstanceId: string,
public readonly workstepInstanceId: string,
public readonly workflowId: string,
public readonly workstepId: string,
public readonly fromSubjectAccountId: string,
public readonly toSubjectAccountId: string,
public readonly payload: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class CreateTransactionCommandHandler
const newTransactionCandidate = this.agent.createNewTransaction(
command.id,
command.nonce,
command.workflowInstanceId,
command.workstepInstanceId,
command.workflowId,
command.workstepId,
subjectAccounts[0],
subjectAccounts[1],
command.payload,
Expand Down
21 changes: 17 additions & 4 deletions examples/bri-3/src/bri/transactions/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ export class Transaction {
@AutoMap()
workflowInstanceId: string;

@AutoMap()
workflowId: string;

@AutoMap()
workstepInstanceId: string;

@AutoMap()
workstepId: string;

@AutoMap()
fromBpiSubjectAccountId: string;

Expand All @@ -40,8 +46,8 @@ export class Transaction {
constructor(
id: string,
nonce: number,
workflowInstanceId: string,
workstepInstanceId: string,
workflowId: string,
workstepId: string,
fromBpiSubjectAccount: BpiSubjectAccount,
toBpiSubjectAccount: BpiSubjectAccount,
payload: string,
Expand All @@ -50,8 +56,8 @@ export class Transaction {
) {
this.id = id;
this.nonce = nonce;
this.workflowInstanceId = workflowInstanceId;
this.workstepInstanceId = workstepInstanceId;
this.workflowId = workflowId;
this.workstepId = workstepId;
this.fromBpiSubjectAccount = fromBpiSubjectAccount;
this.fromBpiSubjectAccountId = fromBpiSubjectAccount?.id;
this.toBpiSubjectAccount = toBpiSubjectAccount;
Expand All @@ -61,6 +67,13 @@ export class Transaction {
this.status = status;
}

public updateWorkflowInstanceId(workflowInstanceId: string): void {
this.workflowInstanceId = workflowInstanceId;
}

public updateWorkstepInstanceId(workstepInstanceId: string): void {
this.workstepInstanceId = workstepInstanceId;
}
public updatePayload(payload: string, signature: string): void {
// TODO: Verify signature
this.payload = payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export class ExecuteVsmCycleCommandHandler
}

const workstep = await this.workstepStorageAgent.getWorkstepById(
tx.workstepInstanceId,
tx.workstepId,
);

const workflow = await this.workflowStorageAgent.getWorkflowById(
tx.workflowInstanceId,
tx.workflowId,
);

try {
Expand Down
8 changes: 4 additions & 4 deletions examples/bri-3/test/sriUseCase.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ async function createWorkflowAndReturnId(
async function createTransactionAndReturnId(
id: string,
nonce: number,
workflowInstanceId: string,
workstepInstanceId: string,
workflowId: string,
workstepId: string,
fromSubjectAccountId: string,
fromPrivatekey: string,
toSubjectAccountId: string,
Expand All @@ -577,8 +577,8 @@ async function createTransactionAndReturnId(
.send({
id: id,
nonce: nonce,
workflowInstanceId: workflowInstanceId,
workstepInstanceId: workstepInstanceId,
workflowId: workflowId,
workstepId: workstepId,
fromSubjectAccountId: fromSubjectAccountId,
toSubjectAccountId: toSubjectAccountId,
payload: payload,
Expand Down
Loading