-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connector-corda): add initial set of JvmObject factory functions
1. These functions are used so more easily construct the JSON representation of JVM objects (references and primitive values) that we need to define when interacting with the Corda JVM connector (which is used for Corda v4 ledgers) 2. This is not a comprehensive set but more like a trailblazing initial implementation to showcase how to create and use these factory functions. Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
Showing
17 changed files
with
362 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,6 +162,7 @@ | |
"Satp", | ||
"sbjpubkey", | ||
"Secp", | ||
"serde", | ||
"shrn", | ||
"Smonitor", | ||
"socketio", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/cactus-plugin-ledger-connector-corda/src/main/typescript/index.web.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
12 changes: 12 additions & 0 deletions
12
...plugin-ledger-connector-corda/src/main/typescript/jvm/serde/factory/create-jvm-boolean.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
42 changes: 42 additions & 0 deletions
42
...connector-corda/src/main/typescript/jvm/serde/factory/create-jvm-cacti-public-key-impl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
], | ||
}; | ||
} |
43 changes: 43 additions & 0 deletions
43
...n-ledger-connector-corda/src/main/typescript/jvm/serde/factory/create-jvm-corda-amount.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
], | ||
}; | ||
} |
29 changes: 29 additions & 0 deletions
29
...-connector-corda/src/main/typescript/jvm/serde/factory/create-jvm-corda-identity-party.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
], | ||
}; | ||
} |
26 changes: 26 additions & 0 deletions
26
...nnector-corda/src/main/typescript/jvm/serde/factory/create-jvm-corda-unique-identifier.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })], | ||
}; | ||
} |
32 changes: 32 additions & 0 deletions
32
...edger-connector-corda/src/main/typescript/jvm/serde/factory/create-jvm-corda-x500-name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), | ||
], | ||
}; | ||
} |
37 changes: 37 additions & 0 deletions
37
...lugin-ledger-connector-corda/src/main/typescript/jvm/serde/factory/create-jvm-currency.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
], | ||
}; | ||
} |
12 changes: 12 additions & 0 deletions
12
...us-plugin-ledger-connector-corda/src/main/typescript/jvm/serde/factory/create-jvm-long.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
28 changes: 28 additions & 0 deletions
28
...-plugin-ledger-connector-corda/src/main/typescript/jvm/serde/factory/create-jvm-string.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.