Skip to content

Commit

Permalink
Merge pull request #154 from perun-network/multi-backend
Browse files Browse the repository at this point in the history
Multi backend
  • Loading branch information
RmbRT authored Apr 30, 2024
2 parents c85a73b + 16780cc commit 7a949d7
Show file tree
Hide file tree
Showing 301 changed files with 31,248 additions and 17,145 deletions.
42 changes: 21 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ jobs:
steps:
- name: "Checkout SDK"
uses: actions/checkout@v3
- name: "Prettier Check"
uses: creyD/[email protected]
with:
dry: True
prettier_options: --config .prettierrc --check **/*.ts
# - name: "Prettier Check"
# uses: creyD/[email protected]
# with:
# dry: True
# prettier_options: --config .prettierrc --check **/*.ts
- name: "Setup Node.js"
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "20"
cache: "yarn"
- name: "Install dependencies"
run: yarn install
- name: "Build"
run: yarn build
- name: "Test"
run: yarn test
- name: "Checkout Erdstall Core"
uses: actions/checkout@v3
with:
ssh-key: ${{ secrets.SSH_PRIV_KEY }}
repository: "perun-network/erdstall-ext"
path: "erdstall"
- name: "Set up Go 1.x"
uses: actions/setup-go@v3
with:
go-version: ^1.17
- name: "Build walkthrough operator"
working-directory: "erdstall"
run: go build -o wo ./cmd/walkthrough/main.go
- name: "End-2-End Test"
run: ERDSTALL_EXE=erdstall/wo yarn test:e2e
# - name: "Checkout Erdstall Core"
# uses: actions/checkout@v3
# with:
# ssh-key: ${{ secrets.SSH_PRIV_KEY }}
# repository: "perun-network/erdstall-ext"
# path: "erdstall"
# - name: "Set up Go 1.x"
# uses: actions/setup-go@v3
# with:
# go-version: ^1.17
# - name: "Build walkthrough operator"
# working-directory: "erdstall"
# run: go build -o wo ./cmd/walkthrough/main.go
# - name: "End-2-End Test"
# run: ERDSTALL_EXE=erdstall/wo yarn test:e2e
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,3 @@ dist

# TernJS port file
.tern-port

# Generated abi bindings
src/ledger/backend/ethereum/abi
src/ledger/backend/ethereum/contracts
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ all: ts

ts:
@yarn install -s
@yarn run build -s
@yarn run build
@echo "Built erdstall-ts-sdk."

bindings:
Expand All @@ -14,6 +14,10 @@ test:
@echo "Compiling and executing tests."
@yarn run test

test-e2e:
@echo "Compiling and executing end-to-end tests."
@yarn run test:e2e:session

integration:
@echo "Compiling and running integration test."
@yarn run test:integration
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ omitted after each event name in the following.
- **`"ChallengeResponded"`**: the Erdstall operator successfully responed with the correct balance proof.

- **`"TokenTypeRegistered"`**: a new token type (such as ETH, ERC20, ERC721, etc.) has been registered with Erdstall on-chain.

- **`"TokenRegistered"`**: a specific token contract has been registered on-chain.
</details>

## Development
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polycrypt/erdstall",
"version": "0.3.0",
"version": "0.3.1",
"description": "SDK to interact with Erdstall Layer-2 Networks",
"main": "./index.js",
"exports": {
Expand Down Expand Up @@ -30,7 +30,9 @@
"lint": "eslint ./src --ext .ts",
"bindings": "./scripts/genbindings.sh",
"test:e2e": "env TS_NODE_PROJECT=\"tsconfig.e2e.json\" mocha -b --timeout 120000 -r jsdom-global/register -r ts-node/register -r tsconfig-paths/register 'src/e2e/**/*.spec.ts'",
"test:e2e:session": "env TS_NODE_PROJECT=\"tsconfig.e2e.json\" mocha -b --timeout 120000 -r jsdom-global/register -r ts-node/register -r tsconfig-paths/register 'src/e2e/operator_e2e.spec.ts'",
"test": "env TS_NODE_PROJECT=\"tsconfig.test.json\" mocha --timeout 15000 -r jsdom-global/register -r ts-node/register -r tsconfig-paths/register 'src/{,!(e2e)/**}/*.spec.ts'",
"test-file": "env TS_NODE_PROJECT=\"tsconfig.test.json\" mocha --timeout 15000 -r jsdom-global/register -r ts-node/register -r tsconfig-paths/register",
"prepack": "yarn build && tsc-alias -p tsconfig.json && ts-node ./scripts/prepack.ts ./package.json ./dist/package.json",
"devpub": "yarn prepack",
"doc": "typedoc ./src ./src/api ./src/enclave ./src/ledger ./src/ledger/backend ./src/test ./src/utils"
Expand Down Expand Up @@ -72,7 +74,7 @@
"ganache": "^7.0.2",
"ganache-cli": "^6.12.2",
"ganache-core": "^2.13.2",
"hardhat": "^2.4.0",
"hardhat": "^2.22.1",
"hardhat-waffle": "^0.0.1-security",
"jsdom": "^16.6.0",
"jsdom-global": "^3.0.2",
Expand All @@ -89,9 +91,13 @@
"walk": "^2.3.14"
},
"dependencies": {
"@polkadot/api": "^10.10.1",
"@polkadot/api-contract": "^10.10.1",
"@polkadot/util-crypto": "^12.5.1",
"axios": "^0.21.4",
"canonicalize": "^2.0.0",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.1",
"ethers": "^6.11.1",
"isomorphic-ws": "^4.0.1",
"number-generator": "^4.0.5",
"reflect-metadata": "^0.1.13",
Expand Down
7 changes: 3 additions & 4 deletions scripts/genbindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ function compileTo() {
# Clean up existing bindings.
rm -rf "${2}"/contracts
mkdir -p "${2}"/contracts/abi
yarn hardhat compile && cp -rl ./typechain/* "${2}"/contracts/ \
yarn hardhat compile && cp -rl ./typechain-types/* "${2}"/contracts/ \
&& find ./artifacts/contracts/*.sol/ \
| grep -v ".dbg" | grep ".json" | xargs cp -l -t "${2}"/contracts/abi/
# Clean up typechain generated files.
rm -rf ./artifacts ./cache ./typechain
rm -rf ./artifacts ./cache ./typechain-types
cd "${CWD}"
}

Expand All @@ -62,8 +62,7 @@ if [[ ! -d $CONTRACTSDIR ]]; then
fi

SRCDIR="${PWD}"
ETHBACKEND="${SRCDIR}"/src/ledger/backend
ETHBACKEND_TEST="${SRCDIR}"/src/test/ledger/backend
ETHBACKEND="${SRCDIR}"/src/ledger/backend/ethereum

checkInstalled npm
checkInstalledLocally typechain
Expand Down
6 changes: 3 additions & 3 deletions src/api/calls/getaccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import { jsonObject, jsonMember } from "#erdstall/export/typedjson";
import { ErdstallObject, registerErdstallType } from "#erdstall/api";
import { Address } from "#erdstall/ledger";
import { Address, Crypto } from "#erdstall/crypto";

const getAccountTypeName = "GetAccount";

@jsonObject
export class GetAccount extends ErdstallObject {
@jsonMember(Address) who: Address;
@jsonMember(Address) who: Address<Crypto>;

constructor(who: Address) {
constructor(who: Address<Crypto>) {
super();
this.who = who;
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/calls/onboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

import { jsonObject, jsonMember } from "#erdstall/export/typedjson";
import { ErdstallObject } from "#erdstall/api";
import { Address } from "#erdstall/ledger";
import { Address, Crypto } from "#erdstall/crypto";

@jsonObject
export class Onboarding extends ErdstallObject {
@jsonMember(Address) who: Address;
@jsonMember(Address) who: Address<Crypto>;

constructor(who: Address) {
constructor(who: Address<Crypto>) {
super();
this.who = who;
}
Expand Down
41 changes: 36 additions & 5 deletions src/api/calls/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

import { ErdstallObject, registerErdstallType } from "#erdstall/api";
import { Address } from "#erdstall/ledger";
import { Address, Crypto } from "#erdstall/crypto";
import { jsonObject, jsonMember } from "#erdstall/export/typedjson";

const subBPsTypeName = "SubscribeBalanceProofs";
Expand All @@ -11,10 +11,10 @@ const subPhaseShiftName = "SubscribePhaseShifts";

@jsonObject
export class SubscribeBalanceProofs extends ErdstallObject {
@jsonMember(Address) who?: Address;
@jsonMember(Address) who?: Address<Crypto>;
@jsonMember(Boolean) cancel?: boolean;

constructor(who?: Address, cancel?: boolean) {
constructor(who?: Address<Crypto>, cancel?: boolean) {
super();
this.who = who;
this.cancel = cancel;
Expand All @@ -23,17 +23,33 @@ export class SubscribeBalanceProofs extends ErdstallObject {
public objectType(): any {
return SubscribeBalanceProofs;
}

protected objectTypeName(): string {
return subBPsTypeName;
}

public static fromJSON(json: any): SubscribeBalanceProofs {
if (!json.who) {
throw new Error("expected who field in subscribe balance proofs");
}
const who = Address.ensure(json.who);
return new SubscribeBalanceProofs(who, json.cancel);
}

public static toJSON(obj: SubscribeBalanceProofs): any {
return {
who: obj.who?.toJSON(),
cancel: obj.cancel,
};
}
}

@jsonObject
export class SubscribeTXs extends ErdstallObject {
@jsonMember(Address) who?: Address;
@jsonMember(Address) who?: Address<Crypto>;
@jsonMember(Boolean) cancel?: boolean;

constructor(who?: Address, cancel?: boolean) {
constructor(who?: Address<Crypto>, cancel?: boolean) {
super();
this.who = who;
this.cancel = cancel;
Expand All @@ -45,6 +61,21 @@ export class SubscribeTXs extends ErdstallObject {
protected objectTypeName(): string {
return subTXsTypeName;
}

// public static fromJSON(json: any): SubscribeTXs {
// if (!json.who) {
// throw new Error("expected who field in subscribe transaction");
// }
// const who = Address.ensure(json.who);
// return new SubscribeTXs(who, json.cancel);
// }

// public static toJSON(obj: SubscribeTXs): any {
// return {
// who: obj.who?.toJSON(),
// cancel: obj.cancel,
// };
// }
}

@jsonObject
Expand Down
1 change: 0 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
export * from "./object";
export * from "./call";
export * from "./result";
export * from "./signature";

export * as calls from "./calls";
export * as responses from "./responses";
4 changes: 2 additions & 2 deletions src/api/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"use strict";

import {
jsonObject,
TypedJSON,
Serializable,
jsonObject,
} from "#erdstall/export/typedjson";
import { customJSON } from "./util";

Expand Down Expand Up @@ -34,7 +34,7 @@ export abstract class ErdstallObject {
return TypedJSON.parse(data, objectImpls.get(js.type)!)!;
}

static toJSON(me: ErdstallObject) {
static toJSON(me: ErdstallObject): any {
return {
type: me.objectTypeName(),
data: JSON.parse(TypedJSON.stringify(me, me.objectType())),
Expand Down
5 changes: 3 additions & 2 deletions src/api/responses/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";

import {
jsonBigIntMember,
jsonU64Member,
jsonObject,
jsonMember,
} from "#erdstall/export/typedjson";
Expand All @@ -14,7 +14,7 @@ const accountTypeName = "AccountResponse";
@jsonObject
export class Account extends ErdstallObject {
@jsonMember(ledger.Account) account: ledger.Account;
@jsonBigIntMember() epoch: bigint;
@jsonU64Member() epoch: bigint;

constructor(account: ledger.Account, epoch: bigint) {
super();
Expand All @@ -25,6 +25,7 @@ export class Account extends ErdstallObject {
public objectType(): any {
return Account;
}

protected objectTypeName(): string {
return accountTypeName;
}
Expand Down
Loading

0 comments on commit 7a949d7

Please sign in to comment.