Skip to content

Commit

Permalink
fix(besu): deployContractSolBytecodeNoKeychainV1 requires keychainId
Browse files Browse the repository at this point in the history
In the DeployContractSolidityBytecodeNoKeychainV1Request of
`packages/cactus-plugin-ledger-connector-besu/src/main/json/openapi.tpl.json`
there are parameters that are required despite the entire point of this
operation is to not need them (e.g. keychainId and contract JSON object).

Fixes #3586

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Oct 17, 2024
1 parent 1a0f661 commit 11dacbc
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,6 @@ components:
web3SigningCredential:
type: null
contractName: contractName
contractJSONString: contractJSONString
gasPrice: gasPrice
properties:
contractName:
Expand All @@ -1038,11 +1037,6 @@ components:
items: {}
nullable: false
type: array
contractJSONString:
description: "For use when not using keychain, pass the contract in as this\
\ string variable"
nullable: false
type: string
constructorArgs:
default: []
items: {}
Expand Down Expand Up @@ -1076,9 +1070,7 @@ components:
- bytecode
- constructorArgs
- contractAbi
- contractJson
- contractName
- keychainId
- web3SigningCredential
type: object
DeployContractSolidityBytecodeV1Response:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,8 @@
"required": [
"contractName",
"contractAbi",
"contractJson",
"bytecode",
"web3SigningCredential",
"keychainId",
"constructorArgs"
],
"additionalProperties": false,
Expand All @@ -787,11 +785,6 @@
"items": {},
"nullable": false
},
"contractJSONString": {
"description": "For use when not using keychain, pass the contract in as this string variable",
"nullable": false,
"type": "string"
},
"constructorArgs": {
"type": "array",
"items": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,8 @@
"required": [
"contractName",
"contractAbi",
"contractJson",
"bytecode",
"web3SigningCredential",
"keychainId",
"constructorArgs"
],
"additionalProperties": false,
Expand All @@ -787,11 +785,6 @@
"items": {},
"nullable": false
},
"contractJSONString": {
"description": "For use when not using keychain, pass the contract in as this string variable",
"nullable": false,
"type": "string"
},
"constructorArgs": {
"type": "array",
"items": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ message DeployContractSolidityBytecodeNoKeychainV1RequestPB {
// The application binary interface of the solidity contract
repeated google.protobuf.Any contractAbi = 512852493;

// For use when not using keychain, pass the contract in as this string variable
string contractJSONString = 405816750;

repeated google.protobuf.Any constructorArgs = 336490508;

Web3SigningCredentialPB web3SigningCredential = 451211679;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ export interface DeployContractSolidityBytecodeNoKeychainV1Request {
* @memberof DeployContractSolidityBytecodeNoKeychainV1Request
*/
'contractAbi': Array<any>;
/**
* For use when not using keychain, pass the contract in as this string variable
* @type {string}
* @memberof DeployContractSolidityBytecodeNoKeychainV1Request
*/
'contractJSONString'?: string;
/**
*
* @type {Array<any>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
constructor(data?: any[] | {
contractName?: string;
contractAbi?: dependency_1.google.protobuf.Any[];
contractJSONString?: string;
constructorArgs?: dependency_1.google.protobuf.Any[];
web3SigningCredential?: dependency_3.org.hyperledger.cacti.plugin.ledger.connector.besu.Web3SigningCredentialPB;
bytecode?: string;
Expand All @@ -31,9 +30,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
if ("contractAbi" in data && data.contractAbi != undefined) {
this.contractAbi = data.contractAbi;
}
if ("contractJSONString" in data && data.contractJSONString != undefined) {
this.contractJSONString = data.contractJSONString;
}
if ("constructorArgs" in data && data.constructorArgs != undefined) {
this.constructorArgs = data.constructorArgs;
}
Expand Down Expand Up @@ -69,12 +65,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
set contractAbi(value: dependency_1.google.protobuf.Any[]) {
pb_1.Message.setRepeatedWrapperField(this, 512852493, value);
}
get contractJSONString() {
return pb_1.Message.getFieldWithDefault(this, 405816750, "") as string;
}
set contractJSONString(value: string) {
pb_1.Message.setField(this, 405816750, value);
}
get constructorArgs() {
return pb_1.Message.getRepeatedWrapperField(this, dependency_1.google.protobuf.Any, 336490508) as dependency_1.google.protobuf.Any[];
}
Expand Down Expand Up @@ -126,7 +116,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
static fromObject(data: {
contractName?: string;
contractAbi?: ReturnType<typeof dependency_1.google.protobuf.Any.prototype.toObject>[];
contractJSONString?: string;
constructorArgs?: ReturnType<typeof dependency_1.google.protobuf.Any.prototype.toObject>[];
web3SigningCredential?: ReturnType<typeof dependency_3.org.hyperledger.cacti.plugin.ledger.connector.besu.Web3SigningCredentialPB.prototype.toObject>;
bytecode?: string;
Expand All @@ -142,9 +131,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
if (data.contractAbi != null) {
message.contractAbi = data.contractAbi.map(item => dependency_1.google.protobuf.Any.fromObject(item));
}
if (data.contractJSONString != null) {
message.contractJSONString = data.contractJSONString;
}
if (data.constructorArgs != null) {
message.constructorArgs = data.constructorArgs.map(item => dependency_1.google.protobuf.Any.fromObject(item));
}
Expand Down Expand Up @@ -172,7 +158,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
const data: {
contractName?: string;
contractAbi?: ReturnType<typeof dependency_1.google.protobuf.Any.prototype.toObject>[];
contractJSONString?: string;
constructorArgs?: ReturnType<typeof dependency_1.google.protobuf.Any.prototype.toObject>[];
web3SigningCredential?: ReturnType<typeof dependency_3.org.hyperledger.cacti.plugin.ledger.connector.besu.Web3SigningCredentialPB.prototype.toObject>;
bytecode?: string;
Expand All @@ -187,9 +172,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
if (this.contractAbi != null) {
data.contractAbi = this.contractAbi.map((item: dependency_1.google.protobuf.Any) => item.toObject());
}
if (this.contractJSONString != null) {
data.contractJSONString = this.contractJSONString;
}
if (this.constructorArgs != null) {
data.constructorArgs = this.constructorArgs.map((item: dependency_1.google.protobuf.Any) => item.toObject());
}
Expand Down Expand Up @@ -221,8 +203,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
writer.writeString(328784197, this.contractName);
if (this.contractAbi.length)
writer.writeRepeatedMessage(512852493, this.contractAbi, (item: dependency_1.google.protobuf.Any) => item.serialize(writer));
if (this.contractJSONString.length)
writer.writeString(405816750, this.contractJSONString);
if (this.constructorArgs.length)
writer.writeRepeatedMessage(336490508, this.constructorArgs, (item: dependency_1.google.protobuf.Any) => item.serialize(writer));
if (this.has_web3SigningCredential)
Expand Down Expand Up @@ -252,9 +232,6 @@ export namespace org.hyperledger.cacti.plugin.ledger.connector.besu {
case 512852493:
reader.readMessage(message.contractAbi, () => pb_1.Message.addToRepeatedWrapperField(message, 512852493, dependency_1.google.protobuf.Any.deserialize(reader), dependency_1.google.protobuf.Any));
break;
case 405816750:
message.contractJSONString = reader.readString();
break;
case 336490508:
reader.readMessage(message.constructorArgs, () => pb_1.Message.addToRepeatedWrapperField(message, 336490508, dependency_1.google.protobuf.Any.deserialize(reader), dependency_1.google.protobuf.Any));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ export async function deployContractV1Keychain(
},
req: DeployContractSolidityBytecodeV1Request,
): Promise<IDeployContractV1KeychainResponse> {
const fnTag = `deployContract()`;
const fnTag = `deployContractV1Keychain()`;
Checks.truthy(req, `${fnTag} req`);

const log = LoggerProvider.getOrCreate({
label: "getBlockV1Impl()",
label: fnTag,
level: ctx.logLevel,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ import { PluginRegistry } from "@hyperledger/cactus-core";
import { PrometheusExporter } from "../../prometheus-exporter/prometheus-exporter";
import Web3 from "web3";
import { transactV1Impl } from "../transact-v1/transact-v1-impl";
import createHttpError from "http-errors";
import { Contract } from "web3-eth-contract";

export interface IDeployContractV1NoKeychainResponse {
contractName: string;
contract: Contract;
contractJsonString: string;
deployResponse: DeployContractSolidityBytecodeV1Response;
}

export async function deployContractV1NoKeychain(
ctx: {
Expand All @@ -33,20 +24,18 @@ export async function deployContractV1NoKeychain(
readonly logLevel: LogLevelDesc;
},
req: DeployContractSolidityBytecodeNoKeychainV1Request,
): Promise<IDeployContractV1NoKeychainResponse> {
): Promise<DeployContractSolidityBytecodeV1Response> {
const fnTag = `deployContractNoKeychain()`;
Checks.truthy(req, `${fnTag} req`);

const log = LoggerProvider.getOrCreate({
label: "getBlockV1Impl()",
label: "deployContractV1NoKeychain()",
level: ctx.logLevel,
});

if (isWeb3SigningCredentialNone(req.web3SigningCredential)) {
throw new Error(`${fnTag} Cannot deploy contract with pre-signed TX`);
}
const { contractName, contractJSONString } = req;
const networkId = await ctx.web3.eth.net.getId();

const tmpContract = new ctx.web3.eth.Contract(req.contractAbi);
const deployment = tmpContract.deploy({
Expand Down Expand Up @@ -95,33 +84,8 @@ export async function deployContractV1NoKeychain(

Checks.truthy(contractAddress, `deployContractNoKeychain():contractAddress`);

if (contractJSONString) {
const networkInfo = { address: contractAddress };
const contractJSON = JSON.parse(contractJSONString);
log.debug("Contract JSON: \n%o", JSON.stringify(contractJSON));
const contract = new ctx.web3.eth.Contract(
contractJSON.abi,
contractAddress || " ",
);
// this.contracts[contractName] = contract;
const network = { [networkId]: networkInfo };
contractJSON.networks = network;

const deployResponse: DeployContractSolidityBytecodeV1Response = {
transactionReceipt: runTxResponse.transactionReceipt,
};
const deployContractV1NoKeychainResponse: IDeployContractV1NoKeychainResponse =
{
contractName: contractName,
contract: contract,
contractJsonString: contractJSONString,
deployResponse: deployResponse,
};
return deployContractV1NoKeychainResponse;
} else {
const errorMessage =
`${fnTag} Cannot create an instance of the contract instance because` +
`the contractName in the request does not exist on the keychain`;
throw new createHttpError[400](errorMessage);
}
const res: DeployContractSolidityBytecodeV1Response = {
transactionReceipt: runTxResponse.transactionReceipt,
};
return res;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function transactV1Signed(
`${fnTag}:req.transactionConfig.rawTransaction`,
);
const log = LoggerProvider.getOrCreate({
label: "getBlockGrpc()",
label: "transactV1Signed()",
level: ctx.logLevel,
});
const rawTx = req.transactionConfig.rawTransaction as string;
Expand All @@ -53,7 +53,7 @@ export async function getTxReceipt(
const fnTag = `getTxReceipt()`;

const log = LoggerProvider.getOrCreate({
label: "getBlockGrpc()",
label: "getTxReceipt",
level: ctx.logLevel,
});
log.debug("Received preliminary receipt from Besu node.");
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function pollForTxReceipt(
): Promise<TransactionReceipt> {
const fnTag = `pollForTxReceipt()`;
const log = LoggerProvider.getOrCreate({
label: "getBlockGrpc()",
label: "pollForTxReceipt()",
level: ctx.logLevel,
});
let txReceipt;
Expand Down
Loading

0 comments on commit 11dacbc

Please sign in to comment.