Skip to content

Commit

Permalink
feat(cactus-plugin-ledger-connector-ethereum): refactor connector API
Browse files Browse the repository at this point in the history
- Refactor to single `invokeContract` endpoint that can accept multiple methods of
    supplying contract definition (directly, from keychain, etc..).
- Same for `deployContract` method.
- Update cactus-common `safeStringifyException` function to better handle axios errors
    (and other custom exceptions that support `toJSON()` method.).
- Use common error handling in all connector endpoints (except prometheus).
- Fix the tests.
- Switch to `Cacti` work in entire connector (except for package name)

Depends on: #2630

Signed-off-by: Michal Bajer <[email protected]>
  • Loading branch information
outSH committed Oct 3, 2023
1 parent c590b81 commit 1171f97
Show file tree
Hide file tree
Showing 30 changed files with 1,033 additions and 1,513 deletions.
11 changes: 11 additions & 0 deletions packages/cactus-common/src/main/typescript/error-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@ export function safeStringifyException(error: unknown): string {
return sanitizeHtml(error.stack || error.message);
}

// Axios and possibly other lib errors produce nicer output with toJSON() method.
// Use it if available
if (
error &&
typeof error === "object" &&
"toJSON" in error &&
typeof error.toJSON === "function"
) {
return sanitizeHtml(error.toJSON());
}

return sanitizeHtml(safeStringify(error));
}
4 changes: 2 additions & 2 deletions packages/cactus-plugin-ledger-connector-ethereum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async transact(req: RunTransactionRequest): Promise<RunTransactionResponse>;
async transactSigned(rawTransaction: string): Promise<RunTransactionResponse>;
async transactGethKeychain(txIn: RunTransactionRequest): Promise<RunTransactionResponse>;
async transactPrivateKey(req: RunTransactionRequest): Promise<RunTransactionResponse>;
async transactCactusKeychainRef(req: RunTransactionRequest):Promise<RunTransactionResponse>;
async transactCactiKeychainRef(req: RunTransactionRequest):Promise<RunTransactionResponse>;
async deployContract(req: DeployContractSolidityBytecodeV1Request :Promise<DeployContractSolidityBytecodeV1Response>;
async deployContractJsonObject(req: DeployContractSolidityBytecodeJsonObjectV1Request): Promise<DeployContractSolidityBytecodeV1Response>
async invokeRawWeb3EthMethod(req: InvokeRawWeb3EthMethodV1Request): Promise<any>;
Expand All @@ -77,7 +77,7 @@ The field "type" can have the following values:
```typescript
enum Web3SigningCredentialType {
CACTUSKEYCHAINREF = "CACTUS_KEYCHAIN_REF",
CACTUSKEYCHAINREF = "CACTI_KEYCHAIN_REF",
GETHKEYCHAINPASSWORD = "GETH_KEYCHAIN_PASSWORD",
PRIVATEKEYHEX = "PRIVATE_KEY_HEX",
NONE = "NONE",
Expand Down
7 changes: 4 additions & 3 deletions packages/cactus-plugin-ledger-connector-ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Allows Cactus nodes to connect to a Ethereum ledger.",
"keywords": [
"Hyperledger",
"Cacti",
"Cactus",
"Integration",
"Blockchain",
Expand All @@ -19,9 +20,9 @@
},
"license": "Apache-2.0",
"author": {
"name": "Hyperledger Cactus Contributors",
"email": "cactus@lists.hyperledger.org",
"url": "https://www.hyperledger.org/use/cactus"
"name": "Hyperledger Cacti Contributors",
"email": "cacti@lists.hyperledger.org",
"url": "https://www.hyperledger.org/use/cacti"
},
"contributors": [
{
Expand Down
Loading

0 comments on commit 1171f97

Please sign in to comment.