Skip to content

Commit

Permalink
feat(besu): record locator
Browse files Browse the repository at this point in the history
Signed-off-by: AzaharaC <a.castano.benito@accenture.com>
  • Loading branch information
AzaharaC authored and petermetz committed Jul 22, 2021
1 parent bc262a2 commit 2410d6d
Show file tree
Hide file tree
Showing 5 changed files with 683 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,33 @@
"PrometheusExporterMetricsResponse": {
"type": "string",
"nullable": false
},
"GetBesuRecordV1Request":{
"type": "object",
"properties": {
"invokeCall": {
"$ref": "#/components/schemas/InvokeContractV1Request"
},
"transactionHash": {
"type": "string",
"minLength": 64,
"maxLength": 64,
"pattern": "/^0x([A-Fa-f0-9]{64})$/"
}
}
},
"GetBesuRecordV1Response":{
"type": "object",
"properties": {
"ledgerId":{
"type":"string"
},
"stateContract":{
"type":"string"
},
"transactionInputData":{},
"callOutput":{}
}
}
}
},
Expand Down Expand Up @@ -1268,6 +1295,40 @@
}
}
}
},
"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-besu-record": {
"post": {
"x-hyperledger-cactus": {
"http": {
"verbLowerCase": "post",
"path": "/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-besu-record"
}
},
"operationId": "getBesuRecordV1",
"summary": "Retrieves an arbitrary record (any piece of information) from the ledger. Ledger records can be call outputs, transaction input, etc.",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetBesuRecordV1Request"
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/GetBesuRecordV1Response"
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,56 @@ export interface GetBalanceV1Response {
*/
balance: string;
}
/**
*
* @export
* @interface GetBesuRecordV1Request
*/
export interface GetBesuRecordV1Request {
/**
*
* @type {InvokeContractV1Request}
* @memberof GetBesuRecordV1Request
*/
invokeCall?: InvokeContractV1Request;
/**
*
* @type {string}
* @memberof GetBesuRecordV1Request
*/
transactionHash?: string;
}
/**
*
* @export
* @interface GetBesuRecordV1Response
*/
export interface GetBesuRecordV1Response {
/**
*
* @type {string}
* @memberof GetBesuRecordV1Response
*/
ledgerId?: string;
/**
*
* @type {string}
* @memberof GetBesuRecordV1Response
*/
stateContract?: string;
/**
*
* @type {any}
* @memberof GetBesuRecordV1Response
*/
transactionInputData?: any | null;
/**
*
* @type {any}
* @memberof GetBesuRecordV1Response
*/
callOutput?: any | null;
}
/**
*
* @export
Expand Down Expand Up @@ -1163,6 +1213,40 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
options: localVarRequestOptions,
};
},
/**
*
* @summary Retrieves an arbitrary record (any piece of information) from the ledger. Ledger records can be call outputs, transaction input, etc.
* @param {GetBesuRecordV1Request} [getBesuRecordV1Request]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getBesuRecordV1: async (getBesuRecordV1Request?: GetBesuRecordV1Request, options: any = {}): Promise<RequestArgs> => {
const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-besu-record`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(getBesuRecordV1Request, localVarRequestOptions, configuration)

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Returns a block matching the block
Expand Down Expand Up @@ -1431,6 +1515,17 @@ export const DefaultApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.getBalanceV1(getBalanceV1Request, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @summary Retrieves an arbitrary record (any piece of information) from the ledger. Ledger records can be call outputs, transaction input, etc.
* @param {GetBesuRecordV1Request} [getBesuRecordV1Request]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getBesuRecordV1(getBesuRecordV1Request?: GetBesuRecordV1Request, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<GetBesuRecordV1Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getBesuRecordV1(getBesuRecordV1Request, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @summary Returns a block matching the block
Expand Down Expand Up @@ -1537,6 +1632,16 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa
getBalanceV1(getBalanceV1Request?: GetBalanceV1Request, options?: any): AxiosPromise<GetBalanceV1Response> {
return localVarFp.getBalanceV1(getBalanceV1Request, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Retrieves an arbitrary record (any piece of information) from the ledger. Ledger records can be call outputs, transaction input, etc.
* @param {GetBesuRecordV1Request} [getBesuRecordV1Request]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getBesuRecordV1(getBesuRecordV1Request?: GetBesuRecordV1Request, options?: any): AxiosPromise<GetBesuRecordV1Response> {
return localVarFp.getBesuRecordV1(getBesuRecordV1Request, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Returns a block matching the block
Expand Down Expand Up @@ -1640,6 +1745,18 @@ export class DefaultApi extends BaseAPI {
return DefaultApiFp(this.configuration).getBalanceV1(getBalanceV1Request, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Retrieves an arbitrary record (any piece of information) from the ledger. Ledger records can be call outputs, transaction input, etc.
* @param {GetBesuRecordV1Request} [getBesuRecordV1Request]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DefaultApi
*/
public getBesuRecordV1(getBesuRecordV1Request?: GetBesuRecordV1Request, options?: any) {
return DefaultApiFp(this.configuration).getBesuRecordV1(getBesuRecordV1Request, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Returns a block matching the block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import {
GetTransactionV1Response,
GetBlockV1Request,
GetBlockV1Response,
GetBesuRecordV1Request,
GetBesuRecordV1Response,
} from "./generated/openapi/typescript-axios";

import { InvokeContractEndpoint } from "./web-services/invoke-contract-endpoint";
Expand All @@ -84,6 +86,7 @@ import { GetTransactionEndpoint } from "./web-services/get-transaction-endpoint"
import { GetPastLogsEndpoint } from "./web-services/get-past-logs-endpoint";
import { RunTransactionEndpoint } from "./web-services/run-transaction-endpoint";
import { GetBlockEndpoint } from "./web-services/get-block-v1-endpoint-";
import { GetBesuRecordEndpointV1 } from "./web-services/get-besu-record-endpoint-v1";

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

Expand Down Expand Up @@ -264,6 +267,13 @@ export class PluginLedgerConnectorBesu
});
endpoints.push(endpoint);
}
{
const endpoint = new GetBesuRecordEndpointV1({
connector: this,
logLevel: this.options.logLevel,
});
endpoints.push(endpoint);
}
{
const opts: IGetPrometheusExporterMetricsEndpointV1Options = {
connector: this,
Expand Down Expand Up @@ -774,4 +784,56 @@ export class PluginLedgerConnectorBesu
const block = await this.web3.eth.getBlock(request.blockHashOrBlockNumber);
return { block };
}
public async getBesuRecord(
request: GetBesuRecordV1Request,
): Promise<GetBesuRecordV1Response> {
const fnTag = `${this.className}#getBesuRecord()`;
//////////////////////////////////////////////
let abi: any = undefined;
const resp: GetBesuRecordV1Response = {};
const txHash = request.transactionHash;

if (txHash) {
const transaction = await this.web3.eth.getTransaction(txHash);
if (transaction.input) {
resp.transactionInputData = transaction.input;
return resp;
}
}

if (request.invokeCall) {
if (request.invokeCall.contractAbi) {
if (typeof request.invokeCall.contractAbi === "string") {
abi = JSON.parse(request.invokeCall.contractAbi);
} else {
abi = request.invokeCall.contractAbi;
}
}
const { contractAddress } = request.invokeCall;
const contractInstance = new this.web3.eth.Contract(abi, contractAddress);
const methodRef = contractInstance.methods[request.invokeCall.methodName];
Checks.truthy(
methodRef,
`${fnTag} YourContract.${request.invokeCall.methodName}`,
);
const method: ContractSendMethod = methodRef(
...request.invokeCall.params,
);

if (
request.invokeCall.invocationType === EthContractInvocationType.Call
) {
const callOutput = await (method as any).call();
const res: GetBesuRecordV1Response = {
callOutput,
};
return res;
} else {
throw new Error(
`${fnTag} Unsupported invocation type ${request.invokeCall.invocationType}`,
);
}
}
return resp;
}
}
Loading

0 comments on commit 2410d6d

Please sign in to comment.