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

feat(connector-corda): add initial set of JvmObject factory functions #3357

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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
"Satp",
"sbjpubkey",
"Secp",
"serde",
"shrn",
"Smonitor",
"socketio",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@
"jvmTypeKind": {
"$ref": "#/components/schemas/JvmTypeKind"
},
"primitiveValue": {
"type": "object"
},
"primitiveValue": {},
"jvmCtorArgs": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@
"$ref": "#/components/schemas/JvmTypeKind"
},
"primitiveValue": {
"type": "object"
},
"jvmCtorArgs": {
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,10 @@ export interface JvmObject {
'jvmTypeKind': JvmTypeKind;
/**
*
* @type {object}
* @type {any}
* @memberof JvmObject
*/
'primitiveValue'?: object;
'primitiveValue'?: any;
/**
*
* @type {Array<JvmObject>}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
export * from "./generated/openapi/typescript-axios/index";

export { createJvmBoolean } from "./jvm/serde/factory/create-jvm-boolean";

export {
ICreateJvmCactiPublicImplKeyOptions,
createJvmCactiPublicKeyImpl,
} from "./jvm/serde/factory/create-jvm-cacti-public-key-impl";

export {
ICreateJvmCordaIdentityPartyOptions,
createJvmCordaIdentityParty,
} from "./jvm/serde/factory/create-jvm-corda-identity-party";

export {
ICreateJvmCordaX500NameOptions,
createJvmCordaX500Name,
} from "./jvm/serde/factory/create-jvm-corda-x500-name";

export { createJvmLong } from "./jvm/serde/factory/create-jvm-long";
export { createJvmCurrency } from "./jvm/serde/factory/create-jvm-currency";

export {
ICreateJvmCordaAmountOptions,
createJvmCordaAmount,
} from "./jvm/serde/factory/create-jvm-corda-amount";

export {
ICreateJvmCordaUniqueIdentifierOptions,
createJvmCordaUniqueIdentifier,
} from "./jvm/serde/factory/create-jvm-corda-unique-identifier";
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";

export function createJvmBoolean(data: boolean): JvmObject {
return {
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "boolean",
},
primitiveValue: data,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";
import { PublicKey } from "../../../generated/openapi/typescript-axios/api";
import { createJvmString } from "./create-jvm-string";

export interface ICreateJvmCactiPublicImplKeyOptions {
readonly publicKey: PublicKey;
}

export function createJvmCactiPublicKeyImpl(
opts: Readonly<ICreateJvmCactiPublicImplKeyOptions>,
): JvmObject {
if (!opts) {
throw new Error("Expected arg1 to be truthy");
}
if (!opts.publicKey) {
throw new Error("Expected arg1.publicKey to be truthy");
}
if (!opts.publicKey.algorithm) {
throw new Error("Expected arg1.publicKey.algorithm to be truthy");
}
if (!opts.publicKey.encoded) {
throw new Error("Expected arg1.publicKey.encoded to be truthy");
}
if (!opts.publicKey.format) {
throw new Error("Expected arg1.publicKey.format to be truthy");
}

return {
jvmTypeKind: JvmTypeKind.Reference,
jvmType: {
fqClassName:
"org.hyperledger.cactus.plugin.ledger.connector.corda.server.impl.PublicKeyImpl",
},

jvmCtorArgs: [
createJvmString({ data: opts.publicKey.algorithm }),
createJvmString({ data: opts.publicKey.format }),
createJvmString({ data: opts.publicKey.encoded }),
],
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";
import { createJvmCurrency } from "./create-jvm-currency";
import { createJvmLong } from "./create-jvm-long";

export interface ICreateJvmCordaAmountOptions {
readonly currencyCode: Readonly<string>;
readonly amount: Readonly<number>;
}

export function createJvmCordaAmount(
opts: Readonly<ICreateJvmCordaAmountOptions>,
): JvmObject {
if (!opts) {
throw new Error("Expected arg1 to be truthy");
}
if (!opts.amount) {
throw new Error("Expected arg1.amount to be truthy");
}
if (!isFinite(opts.amount)) {
throw new Error("Expected arg1.amount to be finite");
}
if (!opts.currencyCode) {
throw new Error("Expected arg1.currencyCode to be truthy");
}
if (typeof opts.currencyCode !== "string") {
throw new Error("Expected arg1.currencyCode to be string");
}
if (opts.currencyCode.length <= 0) {
throw new Error("Expected arg1.currencyCode to be non-blank string");
}
return {
jvmTypeKind: JvmTypeKind.Reference,
jvmType: {
fqClassName: "net.corda.core.contracts.Amount",
},

jvmCtorArgs: [
createJvmLong(opts.amount),
createJvmCurrency({ currencyCode: opts.currencyCode }),
],
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { Party } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";
import { createJvmCactiPublicKeyImpl } from "./create-jvm-cacti-public-key-impl";
import { createJvmCordaX500Name } from "./create-jvm-corda-x500-name";

export interface ICreateJvmCordaIdentityPartyOptions {
readonly party: Readonly<Party>;
}

export function createJvmCordaIdentityParty(
opts: Readonly<ICreateJvmCordaIdentityPartyOptions>,
): JvmObject {
return {
jvmTypeKind: JvmTypeKind.Reference,
jvmType: {
fqClassName: "net.corda.core.identity.Party",
},

jvmCtorArgs: [
createJvmCordaX500Name({
country: opts.party.name.country,
locality: opts.party.name.locality,
organisation: opts.party.name.organisation,
}),
createJvmCactiPublicKeyImpl({ publicKey: opts.party.owningKey }),
],
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";
import { createJvmString } from "./create-jvm-string";

export interface ICreateJvmCordaUniqueIdentifierOptions {
readonly uniqueidentifier: Readonly<string>;
}

export function createJvmCordaUniqueIdentifier(
opts: Readonly<ICreateJvmCordaUniqueIdentifierOptions>,
): JvmObject {
if (!opts) {
throw new Error("Expected arg1 to be truthy");
}
if (!opts.uniqueidentifier) {
throw new Error("Expected arg1.uniqueidentifier to be truthy");
}
return {
jvmTypeKind: JvmTypeKind.Reference,
jvmType: {
fqClassName: "net.corda.core.contracts.UniqueIdentifier",
},

jvmCtorArgs: [createJvmString({ data: opts.uniqueidentifier })],
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";
import { createJvmString } from "./create-jvm-string";

export interface ICreateJvmCordaX500NameOptions {
readonly commonName?: string;
readonly organisationUnit?: string;
readonly organisation: string;
readonly locality: string;
readonly state?: string;
readonly country: string;
}

export function createJvmCordaX500Name(
opts: Readonly<ICreateJvmCordaX500NameOptions>,
): JvmObject {
if (!opts) {
throw new Error("Expected arg1 to be truthy");
}
return {
jvmTypeKind: JvmTypeKind.Reference,
jvmType: {
fqClassName: "net.corda.core.identity.CordaX500Name",
},

jvmCtorArgs: [
createJvmString({ data: opts.organisation }),
createJvmString({ data: opts.locality }),
createJvmString({ data: opts.country }),
],
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";

export interface ICreateJvmCurrencyOptions {
readonly currencyCode: Readonly<string>;
}

export function createJvmCurrency(
opts: Readonly<ICreateJvmCurrencyOptions>,
): JvmObject {
if (!opts) {
throw new Error("Expected arg1 to be truthy");
}
if (!opts.currencyCode) {
throw new Error("Expected arg1.currencyCode to be truthy");
}
if (typeof opts.currencyCode !== "string") {
throw new Error("Expected arg1.currencyCode to be string");
}

return {
jvmTypeKind: JvmTypeKind.Reference,
jvmType: {
fqClassName: "java.util.Currency",
constructorName: "getInstance",
},
jvmCtorArgs: [
{
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: opts.currencyCode,
},
],
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";

export function createJvmLong(data: number): JvmObject {
return {
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "long",
},
primitiveValue: data,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { JvmObject } from "../../../generated/openapi/typescript-axios/api";
import { JvmTypeKind } from "../../../generated/openapi/typescript-axios/api";

export interface ICreateJvmStringOptions {
readonly data: Readonly<string>;
}

export function createJvmString(
opts: Readonly<ICreateJvmStringOptions>,
): JvmObject {
if (!opts) {
throw new Error("Expected arg1 to be truthy");
}
if (!opts.data) {
throw new Error("Expected arg1.data to be truthy");
}
if (typeof opts.data !== "string") {
throw new Error("Expected arg1.data to be string");
}

return {
jvmTypeKind: JvmTypeKind.Primitive,
jvmType: {
fqClassName: "java.lang.String",
},
primitiveValue: opts.data,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,33 @@ export {
CordaApiClientOptions,
watchBlocksV1Options,
} from "./api-client/corda-api-client";

export { createJvmBoolean } from "./jvm/serde/factory/create-jvm-boolean";

export {
ICreateJvmCactiPublicImplKeyOptions,
createJvmCactiPublicKeyImpl,
} from "./jvm/serde/factory/create-jvm-cacti-public-key-impl";

export {
ICreateJvmCordaIdentityPartyOptions,
createJvmCordaIdentityParty,
} from "./jvm/serde/factory/create-jvm-corda-identity-party";

export {
ICreateJvmCordaX500NameOptions,
createJvmCordaX500Name,
} from "./jvm/serde/factory/create-jvm-corda-x500-name";

export { createJvmLong } from "./jvm/serde/factory/create-jvm-long";
export { createJvmCurrency } from "./jvm/serde/factory/create-jvm-currency";

export {
ICreateJvmCordaAmountOptions,
createJvmCordaAmount,
} from "./jvm/serde/factory/create-jvm-corda-amount";

export {
ICreateJvmCordaUniqueIdentifierOptions,
createJvmCordaUniqueIdentifier,
} from "./jvm/serde/factory/create-jvm-corda-unique-identifier";
Loading
Loading