Skip to content

Commit

Permalink
feat(satp-hermes): gateway runner and docker for SATP
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Mateus <brumat315@gmail.com>

refactor(satp-hermes): gateway container image definition with bundler

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>

refactor(satp-hermes): merge policies type guard example

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>

refactor(satp-hermes): type guards for SATP env variables

Signed-off-by: Bruno Mateus <brumat315@gmail.com>

squash! - peter's fixes for besu connectivity use LAN IP

Instead of hardcoded localhost use the LAN IP of machine so that the
gateway container can access it too.

Why though? Because if you tell the gateway container that it should
access the besu ledger via localhost then it will try to do that through
the container's own localhost, which is different from the host machine's
localhost (where the besu ledger is actually running).

Using the actual IP address of the host machine's primary network interface
resolves the ambiguity between the two differnet localhosts.

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>

fix(besu): deployContractSolBytecodeNoKeychainV1 requires keychainId

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 hyperledger-cacti#3586

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
brunoffmateus committed Oct 24, 2024
1 parent dd47d6a commit 817b10b
Show file tree
Hide file tree
Showing 70 changed files with 5,187 additions and 580 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ httpModule
if (exitCode === 0) {
console.log("%s Healthcheck OK: ", url, statusCode, statusMessage);
} else {
console.error("%s Healthcheck FAIL: ", url, statusCode, statusMessage);
console.error("%s Healthcheck FAIL_1: ", url, statusCode, statusMessage);
}
process.exit(exitCode);
})
.on("error", (ex) => {
console.error("%s Healthcheck FAIL: ", url, ex);
console.error("%s Healthcheck FAIL_2: ", url, ex);
process.exit(1);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IPluginFactoryOptions } from "@hyperledger/cactus-core-api";
import { PluginFactoryBungeeHermes } from "./plugin-factory-bungee-hermes";

export { isMergePolicyValueArray } from "./view-merging/merge-policies";
export { isPrivacyPolicyValueArray } from "./view-creation/privacy-policies";

export {
PluginBungeeHermes,
IPluginBungeeHermesOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ export interface IPrivacyPolicyValue {
policy: PrivacyPolicyOpts;
policyHash: string;
}

// Type guard for PrivacyPolicyOpts
export function isPrivacyPolicyOpts(
value: unknown,
): value is PrivacyPolicyOpts {
return (
typeof value === "string" &&
Object.values(PrivacyPolicyOpts).includes(value as PrivacyPolicyOpts)
);
}

// Type guard for IPrivacyPolicyValue
export function isPrivacyPolicyValue(obj: unknown): obj is IPrivacyPolicyValue {
return (
typeof obj === "object" &&
obj !== null &&
"policy" in obj && // Ensure 'policy' key exists
isPrivacyPolicyOpts((obj as Record<string, unknown>).policy) && // Check if policy is a valid PrivacyPolicyOpts value
typeof (obj as Record<string, unknown>).policyHash === "string" // Ensure 'policyHash' is a string
);
}

// Type guard for an array of IPrivacyPolicyValue
export function isPrivacyPolicyValueArray(
input: unknown,
): input is Array<IPrivacyPolicyValue> {
return Array.isArray(input) && input.every(isPrivacyPolicyValue);
}

export class PrivacyPolicies {
constructor() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ export interface IMergePolicyValue {
policy: MergePolicyOpts;
policyHash?: string; //undefined if policy is NONE
}

// Type guard for MergePolicyOpts
export function isMergePolicyOpts(value: unknown): value is MergePolicyOpts {
return (
typeof value === "string" &&
Object.values(MergePolicyOpts).includes(value as MergePolicyOpts)
);
}

// Type guard for IMergePolicyValue
export function isMergePolicyValue(obj: unknown): obj is IMergePolicyValue {
return (
typeof obj === "object" &&
obj !== null &&
"policy" in obj && // Ensure 'policy' key exists
isMergePolicyOpts((obj as Record<string, unknown>).policy) && // Check if policy is a valid MergePolicyOpts value
(typeof (obj as Record<string, unknown>).policyHash === "string" ||
typeof (obj as Record<string, unknown>).policyHash === "undefined") // Ensure 'policyHash' is either a string or undefined
);
}

// Type guard for an array of IMergePolicyValue
export function isMergePolicyValueArray(
input: unknown,
): input is IMergePolicyValue[] {
return Array.isArray(input) && input.every(isMergePolicyValue);
}

export class MergePolicies {
constructor() {}

Expand Down
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
Loading

0 comments on commit 817b10b

Please sign in to comment.