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 Sep 11, 2023
1 parent 9a7dc2c commit 4540c1b
Show file tree
Hide file tree
Showing 31 changed files with 1,030 additions and 1,513 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1593,13 +1593,13 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
- run: ./tools/ci.sh

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run solidity tests
run: cd packages/cactus-plugin-htlc-eth-besu && forge test -vvvvv

cactus-test-plugin-htlc-eth-besu-erc20:
continue-on-error: false
env:
Expand Down
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 @@ -51,7 +51,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 @@ -76,7 +76,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
9 changes: 5 additions & 4 deletions packages/cactus-plugin-ledger-connector-ethereum/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@hyperledger/cactus-plugin-ledger-connector-ethereum",
"version": "2.0.0-alpha.1",
"description": "Allows Cactus nodes to connect to a Ethereum ledger.",
"description": "Allows Cacti 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 4540c1b

Please sign in to comment.