Skip to content

Commit

Permalink
feat(cactus-connector-besu): add RunTransactionV1Exchange to share re…
Browse files Browse the repository at this point in the history
…ceipt data

Authored-by: Bruno Mateus [email protected]
Co-authored-by: Rafael Belchior [email protected]
Signed-off-by: Rafael Belchior [email protected]
  • Loading branch information
RafaelAPB committed Nov 15, 2024
1 parent 4424bf9 commit 5719c7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ import { getBlockV1Http } from "./impl/get-block-v1/get-block-v1-http";
import { transactV1Impl } from "./impl/transact-v1/transact-v1-impl";
import { deployContractV1Keychain } from "./impl/deploy-contract-v1/deploy-contract-v1-keychain";
import { deployContractV1NoKeychain } from "./impl/deploy-contract-v1/deploy-contract-v1-no-keychain";
import { ReplaySubject, Observable } from "rxjs";

export interface RunTransactionV1Exchange {
request: InvokeContractV1Request;
response: RunTransactionResponse;
timestamp: Date;
}

export const E_KEYCHAIN_NOT_FOUND = "cactus.connector.besu.keychain_not_found";

Expand Down Expand Up @@ -141,6 +148,8 @@ export class PluginLedgerConnectorBesu
} = {};

private endpoints: IWebServiceEndpoint[] | undefined;
private txSubject: ReplaySubject<RunTransactionV1Exchange> =
new ReplaySubject();

public static readonly CLASS_NAME = "PluginLedgerConnectorBesu";

Expand Down Expand Up @@ -196,6 +205,10 @@ export class PluginLedgerConnectorBesu
return this.instanceId;
}

public getTxSubjectObservable(): Observable<RunTransactionV1Exchange> {
return this.txSubject.asObservable();
}

public async onPluginInit(): Promise<void> {
this.web3Quorum = Web3JsQuorum(this.web3);
this.log.info("onPluginInit() querying networkId...");
Expand Down Expand Up @@ -428,6 +441,7 @@ export class PluginLedgerConnectorBesu
req: InvokeContractV1Request,
): Promise<InvokeContractV1Response> {
const fnTag = `${this.className}#invokeContract()`;

const contractName = req.contractName;
let contractInstance: Contract;

Expand Down Expand Up @@ -606,6 +620,16 @@ export class PluginLedgerConnectorBesu
const out = await this.transact(txReq);
const success = out.transactionReceipt.status;
const data = { success, out };

// create RunTransactionV1Exchange for transaction monitoring
const receiptData: RunTransactionV1Exchange = {
request: req,
response: out,
timestamp: new Date(),
};
this.log.debug(`RunTransactionV1Exchange created ${receiptData}`);
this.txSubject.next(receiptData);

return data;
} else {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export {
E_KEYCHAIN_NOT_FOUND,
IPluginLedgerConnectorBesuOptions,
PluginLedgerConnectorBesu,
RunTransactionV1Exchange,
} from "./plugin-ledger-connector-besu";
export { PluginFactoryLedgerConnector } from "./plugin-factory-ledger-connector";

Expand Down

0 comments on commit 5719c7b

Please sign in to comment.