-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>
- Loading branch information
Showing
28 changed files
with
918 additions
and
87 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
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
3 changes: 3 additions & 0 deletions
3
...cactus-plugin-satp-hermes/src/main/typescript/api1/oracle/oracle-execute-task.endpoint.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,3 @@ | ||
// interfaces api1(http) with gateway. calls oracle-execute-task | ||
|
||
// todo load endpoints in the dispatcher |
16 changes: 16 additions & 0 deletions
16
packages/cactus-plugin-satp-hermes/src/main/typescript/api1/oracle/oracle-execute-task.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,16 @@ | ||
// todo implement service by calling internal compomnents (public functions of oracle manager) | ||
/* | ||
GOAL | ||
Goal is to implement an oracle that allows data transfers, keeping accountability. gateway notarizes data (produces a proof with bungee) and persists the data on target + notarization | ||
IDEA: | ||
instead of Register data transfer task,that is ran on specific conditions, do a one-time data transfer task | ||
input parameters include | ||
4. if event name, then also event fields 5. if function endponit, which method and parameters | ||
6. session id (for data transfer) | ||
7. (optional) callbackurl for notifications | ||
smart contract addresses, functions, and parameters for source and target chains, etc | ||
returns an ID (of data transfer task, taskID) to be used in the status endpoint; | ||
*/ |
3 changes: 3 additions & 0 deletions
3
...s/cactus-plugin-satp-hermes/src/main/typescript/api1/oracle/oracle-get-status-endpoint.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,3 @@ | ||
// interfaces api1(http) with gateway. calls oracle-get-status | ||
|
||
// todo load endpoints in the dispatcher |
7 changes: 7 additions & 0 deletions
7
packages/cactus-plugin-satp-hermes/src/main/typescript/api1/oracle/oracle-get-status.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,7 @@ | ||
// todo implement service by calling internal compomnents (public functions of oracle manager) | ||
/* | ||
user provides the status id given by register endpoint, and gets a status | ||
TBD define data model for status, suggestion: NOT_FOUND, INVALID, PENDING, SUCCESS, FAILED | ||
returns a status and useful data to confirm such status (eg bungee notarizations, tx hashes, etc) | ||
*/ |
3 changes: 3 additions & 0 deletions
3
...actus-plugin-satp-hermes/src/main/typescript/api1/oracle/oracle-register-task-endpoint.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,3 @@ | ||
// interfaces api1(http) with gateway. calls oracle-register-task | ||
|
||
// todo load endpoints in the dispatcher |
22 changes: 22 additions & 0 deletions
22
packages/cactus-plugin-satp-hermes/src/main/typescript/api1/oracle/oracle-register-task.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,22 @@ | ||
// todo implement service by calling internal compomnents (public functions of oracle manager) | ||
/* | ||
GOAL | ||
Goal is to implement an oracle that allows data transfers, keeping accountability. gateway notarizes data (produces a proof with bungee) and persists the data on target + notarization | ||
IDEA: | ||
Register data transfer task (automatic data transfer, needs trigger conditions)ORexecute data transfer task (perform one data transfer at current time) | ||
General Config includes: | ||
1. Source and target chain id | ||
2. Source and target chain contract id | ||
3. Source chain contract event name or function endpoint | ||
4. if event name, then also event fields 5. if function endponit, which method and parameters | ||
6. session id (for data transfer) | ||
7. (optional) callbackurl for notifications | ||
config for automatic data transfer | ||
8. trigger conditions (eg fire event, return value on certain function call changes, time, | ||
returns an ID (of data transfer task, taskID) to be used in the status endpoint; | ||
*/ |
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
60 changes: 60 additions & 0 deletions
60
...s-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/oracle/oracle-abstract.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,60 @@ | ||
//// filepath: /Users/rafaelapb/Projects/blockchain-integration-framework/packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/oracle/oracle-abstract.ts | ||
import type { | ||
LogLevelDesc, | ||
} from "@hyperledger/cactus-common"; | ||
import type { PluginBungeeHermes } from "@hyperledger/cactus-plugin-bungee-hermes"; | ||
import type { TransactionResponse } from "../../types/blockchain-interaction"; | ||
|
||
/** | ||
* Common interface options for all Oracles. | ||
*/ | ||
export interface OracleAbstractOptions { | ||
bungee: PluginBungeeHermes; | ||
logLevel?: LogLevelDesc; | ||
} | ||
|
||
/** | ||
* Data structure for updating the ledger with some payload. | ||
*/ | ||
export interface UpdateOracleEntryBase { | ||
header: { | ||
targetChainId: string; | ||
sequenceNumber: number; | ||
}; | ||
payload: string; | ||
} | ||
|
||
/** | ||
* Data structure for reading from the ledger (method name, contract, etc.). | ||
*/ | ||
export interface ReadEntryArgsBase { | ||
chainId: string; | ||
contractId: string; | ||
methodName: string; | ||
params?: any[]; | ||
} | ||
|
||
export abstract class OracleAbstract { | ||
protected readonly config: any; | ||
public network: string; | ||
|
||
constructor(options: OracleAbstractOptions) { | ||
this.network = this.config?.network?.id || ""; | ||
} | ||
|
||
/** | ||
* Method to update the ledger with some payload. | ||
* Must be implemented by subclass (Fabric/EVM, etc.). | ||
*/ | ||
public abstract updateEntry( | ||
entry: UpdateOracleEntryBase, | ||
): Promise<{ transactionResponse: TransactionResponse; proof: any }>; | ||
|
||
/** | ||
* Method to read from the ledger (e.g., query a method). | ||
* Must be implemented by subclass. | ||
*/ | ||
public abstract readEntry( | ||
args: ReadEntryArgsBase, | ||
): Promise<{ callOutput: any; proof: any }>; | ||
} |
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,169 @@ | ||
import { | ||
OracleAbstract, | ||
type OracleAbstractOptions, | ||
type UpdateOracleEntryBase, | ||
type ReadEntryArgsBase, | ||
} from "./oracle-abstract"; | ||
import type { TransactionResponse } from "../../types/blockchain-interaction"; | ||
import { | ||
EthContractInvocationType, | ||
PluginLedgerConnectorBesu, | ||
type Web3SigningCredential, | ||
} from "@hyperledger/cactus-plugin-ledger-connector-besu"; | ||
import safeStableStringify from "safe-stable-stringify"; | ||
import { | ||
type Logger, | ||
LoggerProvider, | ||
type LogLevelDesc, | ||
} from "@hyperledger/cactus-common"; | ||
import type { | ||
IPluginBungeeHermesOptions, | ||
PluginBungeeHermes, | ||
} from "@hyperledger/cactus-plugin-bungee-hermes"; | ||
import type { IPluginLedgerConnectorEthereumOptions } from "@hyperledger/cactus-plugin-ledger-connector-ethereum"; | ||
|
||
export interface UpdateEVMOracleTransactionConfig { | ||
contractName: string; | ||
keychainId: string; | ||
signingCredential: Web3SigningCredential; | ||
gas: number; | ||
network: { | ||
id: string; | ||
ledgerType: string; | ||
}; | ||
options: any; | ||
bungeeOptions: IPluginBungeeHermesOptions; | ||
} | ||
|
||
export interface UpdateEVMOracleEntry extends UpdateOracleEntryBase {} | ||
export interface ReadEntryArgs extends ReadEntryArgsBase {} | ||
|
||
export interface OracleEVMOptions extends OracleAbstractOptions { | ||
oracleConfig: UpdateEVMOracleTransactionConfig; | ||
connectorConfig: IPluginLedgerConnectorEthereumOptions; | ||
} | ||
export class OracleEVM extends OracleAbstract { | ||
public static CLASS_NAME = "OracleAbstract"; | ||
private readonly connector: PluginLedgerConnectorBesu; | ||
protected readonly config: UpdateEVMOracleTransactionConfig; | ||
private readonly logger: Logger; | ||
private readonly bungee: PluginBungeeHermes; | ||
|
||
constructor(options: OracleEVMOptions, level?: LogLevelDesc) { | ||
super({ | ||
bungee: options.bungee, | ||
logLevel: level || options.logLevel, | ||
}); | ||
const label = OracleEVM.CLASS_NAME; | ||
this.logger = LoggerProvider.getOrCreate({ label, level: level || "INFO" }); | ||
this.config = options.oracleConfig; | ||
this.connector = new PluginLedgerConnectorBesu(this.config.options); | ||
this.network = this.config.network.id; | ||
this.bungee = options.bungee; | ||
} | ||
|
||
public async updateEntry( | ||
entry: UpdateEVMOracleEntry, | ||
): Promise<{ transactionResponse: TransactionResponse; proof: any }> { | ||
const fnTag = `${OracleEVM.CLASS_NAME}#updateEntry`; | ||
this.logger.debug( | ||
`${fnTag}: Updating entry with header: ${safeStableStringify(entry.header)}`, | ||
); | ||
|
||
const response = (await this.connector.invokeContract({ | ||
contractName: this.config.contractName, | ||
keychainId: this.config.keychainId, | ||
invocationType: EthContractInvocationType.Send, | ||
methodName: "UpdateEVMOracleEntry", | ||
params: [ | ||
entry.header.targetChainId, | ||
entry.header.sequenceNumber.toString(), | ||
entry.payload, | ||
], | ||
signingCredential: this.config.signingCredential, | ||
gas: this.config.gas, | ||
})) as { | ||
success: boolean; | ||
out: { transactionReceipt: { transactionHash?: string } }; | ||
}; | ||
|
||
if (!response.success) { | ||
throw new Error(`${fnTag}: EVM transaction failed`); | ||
} | ||
|
||
const transactionResponse: TransactionResponse = { | ||
transactionId: response.out.transactionReceipt.transactionHash ?? "", | ||
transactionReceipt: | ||
safeStableStringify(response.out.transactionReceipt) ?? "", | ||
}; | ||
|
||
const networkDetails = { | ||
signingCredential: this.config.signingCredential, | ||
contractName: this.config.contractName, | ||
connectorApiPath: this.network, | ||
keychainId: this.config.keychainId, | ||
contractAddress: "", | ||
participant: "", | ||
}; | ||
|
||
const snapshot = await this.bungee.generateSnapshot( | ||
[], | ||
"ORACLE_EVM", | ||
networkDetails, | ||
); | ||
const proof = this.bungee.generateView( | ||
snapshot, | ||
"0", | ||
Number.MAX_SAFE_INTEGER.toString(), | ||
undefined, | ||
); | ||
|
||
return { transactionResponse, proof }; | ||
} | ||
|
||
public async readEntry( | ||
args: ReadEntryArgs, | ||
): Promise<{ callOutput: any; proof: any }> { | ||
const fnTag = `${OracleEVM.CLASS_NAME}#readEntry`; | ||
this.logger.debug( | ||
`${fnTag}: Reading entry with args: ${safeStableStringify(args)}`, | ||
); | ||
|
||
const response = (await this.connector.invokeContract({ | ||
contractName: args.contractId, | ||
keychainId: this.config.keychainId, | ||
invocationType: EthContractInvocationType.Call, | ||
methodName: args.methodName, | ||
params: args.params || [], | ||
signingCredential: this.config.signingCredential, | ||
gas: this.config.gas, | ||
})) as { success: boolean; callOutput: any }; | ||
|
||
if (!response.success) { | ||
throw new Error(`${fnTag}: EVM read transaction failed`); | ||
} | ||
|
||
const networkDetails = { | ||
signingCredential: this.config.signingCredential, | ||
contractName: this.config.contractName, | ||
connectorApiPath: this.network, | ||
keychainId: this.config.keychainId, | ||
contractAddress: "", | ||
participant: "", | ||
}; | ||
|
||
const snapshot = await this.bungee.generateSnapshot( | ||
[], | ||
"ORACLE_EVM", | ||
networkDetails, | ||
); | ||
const proof = this.bungee.generateView( | ||
snapshot, | ||
"0", | ||
Number.MAX_SAFE_INTEGER.toString(), | ||
undefined, | ||
); | ||
|
||
return { callOutput: response.callOutput, proof }; | ||
} | ||
} |
Oops, something went wrong.