Skip to content

Commit

Permalink
Merge branch 'main' into CedarMist/feature/clients-py
Browse files Browse the repository at this point in the history
  • Loading branch information
CedarMist authored Nov 13, 2023
2 parents 9b60b44 + e7897fc commit 132aed1
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 53 deletions.
22 changes: 22 additions & 0 deletions .github/wait-until-ready.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
set -o pipefail
SECONDS=0
TIMEOUT=30
OASIS_WEB3_GATEWAY=http://127.0.0.1:8545

gatewayisready() {
curl -X POST -s \
-H 'Content-Type: application/json' \
--data '{"jsonrpc":"2.0","method":"oasis_callDataPublicKey","params":[],"id":1}' \
${OASIS_WEB3_GATEWAY} 2>&1 | jq -e '.result | has("key")'
}

until gatewayisready
do
if (( SECONDS >= TIMEOUT ))
then
echo "Gateway not ready..."
exit 1
fi
sleep 1
done
2 changes: 1 addition & 1 deletion .github/workflows/ci-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/contracts-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches:
- main
jobs:
hardhat-test:
contracts-test:
runs-on: ubuntu-latest
services:
sapphire-dev-ci:
Expand All @@ -22,19 +22,19 @@ jobs:
--health-cmd="/oasis-node debug control wait-ready -a unix:/serverdir/node/net-runner/network/client-0/internal.sock"
--health-start-period=90s
steps:
- name: attempt to connect to sapphire-dev-ci
run: curl -kv http://sapphire-dev-ci:8545/ || true
- name: attempt to connect to sapphire-dev-ci via localhost
run: curl -kv http://127.0.0.1:8545/ || true
- name: Checkout code
uses: actions/checkout@v4
- name: Install jq
run: sudo apt install -y jq
- name: Wait for gateway
run: bash .github/wait-until-ready.sh
- name: Python client tests
working-directory: clients/py
run: |
python3 -mpip install --user -r requirements.txt
python3 -munittest discover
- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/[email protected]
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Build hardhat integration
working-directory: integrations/hardhat
run: pnpm build
- name: hardhat test contracts
- name: Test contracts with Hardhat
working-directory: contracts
run: pnpm hardhat test --network sapphire-dev-ci
- name: Build docs
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"
- name: Extract package from tag
Expand All @@ -22,5 +22,7 @@ jobs:
- name: Publish ${{ github.ref_name }} to NPM
uses: JS-DevTools/npm-publish@v3
with:
# Build runs as a prepublish script
ignore-scripts: false
token: ${{ secrets.NPM_TOKEN }}
package: ${{ steps.extract-tag.outputs.NPM_PACKAGE }}
4 changes: 2 additions & 2 deletions clients/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To build and test locally, import the `Go` package.
### Go-Ethereum ABI

After [generating](https://geth.ethereum.org/docs/dapp/abigen) the Go bindings
for a particular Solidity contract, you can use dial an Ethereum client with the
for a particular Solidity contract, you can instantiate an Ethereum client with the
Sapphire Paratime gateway URL and instantiate a `sapphire.WrappedBackend` as a drop in
replacement.

Expand Down Expand Up @@ -54,7 +54,7 @@ packedTx := sapphire.PackTx(tx, sapphire.NewCipher(sapphireTestnetChainId))
signedTx := sign(packedTx) // using your usual signer
```

and sending it with an normal, not-wrapped `ethclient`:
and sending it with a normal, not-wrapped `ethclient`:

```Go
ethclient.SendTransaction(ctx, signedTx)
Expand Down
20 changes: 5 additions & 15 deletions clients/go/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (
)

const (
DefaultGasPrice = 100_000_000_000
// DefaultGasLimit is set on all transactions without explicit gas limit to avoid being set on signed queries by the web3 gateway.
DefaultGasLimit = 30_000_000
DefaultGasPrice = 100_000_000_000
DefaultBlockRange = 15
)

Expand Down Expand Up @@ -76,7 +74,7 @@ func PackCall(msg ethereum.CallMsg, cipher Cipher) (*ethereum.CallMsg, error) {

// PackSignedCall prepares `msg` in-place for being sent to Sapphire. The call will be end-to-end encrypted and a signature will be used to authenticate the `from` address.
func PackSignedCall(msg ethereum.CallMsg, cipher Cipher, sign SignerFn, chainID big.Int, leash Leash) (*ethereum.CallMsg, error) {
dataPack, err := NewDataPack(sign, chainID.Uint64(), msg.From[:], msg.To[:], DefaultGasLimit, msg.GasPrice, msg.Value, msg.Data, leash)
dataPack, err := NewDataPack(sign, chainID.Uint64(), msg.From[:], msg.To[:], 0, msg.GasPrice, msg.Value, msg.Data, leash)
if err != nil {
return nil, fmt.Errorf("failed to create signed call data back: %w", err)
}
Expand Down Expand Up @@ -158,7 +156,7 @@ func (b WrappedBackend) Transactor(from common.Address) *bind.TransactOpts {
From: from,
Signer: signFn,
GasPrice: big.NewInt(DefaultGasPrice),
GasLimit: DefaultGasLimit,
GasLimit: 0,
}
}

Expand Down Expand Up @@ -230,16 +228,8 @@ func (b WrappedBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)

// EstimateGas implements ContractTransactor.
func (b WrappedBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) {
return DefaultGasLimit, nil
// TODO(#39)
// header, err := b.backend.HeaderByNumber(ctx, blockNumber)
// if err != nil {
// return nil, err
// }
// if err = packContractCall(header, &call, b.ChainID.Uint64(), b.Signer, b.Cipher); err != nil {
// return nil, err
// }
// return b.backend.EstimateGas(ctx, call)
// Assume latest round in oasis-web3-gateway RPC call
return b.backend.EstimateGas(ctx, call)
}

func txNeedsPacking(tx *types.Transaction) bool {
Expand Down
22 changes: 2 additions & 20 deletions clients/js/src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ export type SapphireAnnex = {
};
};

/** If a gas limit is not provided, the runtime will produce a very confusing error message, so we set a default limit. This one is very high, but solves the problem. This should be lowered once error messages are better or gas estimation is enabled. */
const DEFAULT_GAS = 10_000_000;

/**
* Wraps an upstream ethers/web3/EIP-1193 provider to speak the Sapphire format.
*
Expand Down Expand Up @@ -165,7 +162,7 @@ export function wrap<U extends UpstreamProvider>(
cipher,
),
call: hookEthers6Call(signer, 'call', cipher),
estimateGas: async () => BigInt(DEFAULT_GAS),
estimateGas: hookEthers6Call(signer, 'estimateGas', cipher),
connect(provider: ethers6.Provider) {
return wrap(
signer.connect(provider) as unknown as ethers6.Signer,
Expand Down Expand Up @@ -200,13 +197,7 @@ export function wrap<U extends UpstreamProvider>(
cipher,
),
call: hookEthers5Call(signer, 'call', cipher),
// TODO(#39): replace with original once resolved
estimateGas: async () => BigNumber.from(DEFAULT_GAS),
// estimateGas: hookEthersCall(
// signer.estimateGas.bind(signer),
// cipher,
// signer,
// ),
estimateGas: hookEthers5Call(signer, 'estimateGas', cipher),
connect(provider: AbstractProvider) {
return wrap(
signer.connect(provider) as unknown as Ethers5Signer,
Expand Down Expand Up @@ -438,15 +429,13 @@ function hookEthers5Send(send: Ethers5Call, cipher: Cipher): Ethers5Call {
return async (tx: Deferrable<TransactionRequest>, ...rest) => {
const data = await tx.data;
tx.data = cipher.encryptEncode(data);
if (!tx.gasLimit) tx.gasLimit = DEFAULT_GAS;
return send(tx, ...rest);
};
}

function hookEthers6Send(send: Ethers6Call, cipher: Cipher): Ethers6Call {
return async (tx: ethers6.TransactionRequest, ...rest) => {
if (tx.data) tx.data = await cipher.encryptEncode(tx.data);
if (!tx.gasLimit) tx.gasLimit = DEFAULT_GAS;
return send(tx, ...rest);
};
}
Expand Down Expand Up @@ -482,8 +471,6 @@ function hookExternalSigner(
cipher: Cipher,
): EIP1193Provider['request'] {
return async (args: Web3ReqArgs) => {
if (args.method === 'eth_estimateGas')
return BigNumber.from(DEFAULT_GAS).toHexString(); // TODO(#39)
const { method, params } = await prepareRequest(args, signer, cipher);
const res = await signer.provider.send(method, params ?? []);
if (method === 'eth_call') return cipher.decryptEncoded(res);
Expand All @@ -496,11 +483,8 @@ function hookExternalProvider(
cipher: Cipher,
): EIP1193Provider['request'] {
return async ({ method, params }: Web3ReqArgs) => {
if (method === 'eth_estimateGas')
return BigNumber.from(DEFAULT_GAS).toHexString(); // TODO(#39)
if (method === 'eth_call' && params) {
params[0].data = await cipher.encryptEncode(params[0].data);
if (!params[0].gasLimit) params[0].gasLimit = DEFAULT_GAS;
return provider.send(method, params);
}
return provider.send(method, params ?? []);
Expand Down Expand Up @@ -546,7 +530,6 @@ async function prepareRequest(

if (/^eth_((send|sign)Transaction|call|estimateGas)$/.test(method)) {
params[0].data = await cipher.encryptEncode(params[0].data);
if (!params[0].gasLimit) params[0].gasLimit = DEFAULT_GAS;
return { method, params };
}

Expand Down Expand Up @@ -594,7 +577,6 @@ async function repackRawTx(
value: q(tx.value),
chainId: Number(tx.chainId),
};
if (!parsed.gasLimit) parsed.gasLimit = q(BigInt(DEFAULT_GAS)); // TODO(39)
try {
return signer!.signTransaction({
...parsed,
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/signed_calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async function makeLeash(
const [nonce, block] = await Promise.all([nonceP, blockP]);
const blockRange = overrides?.blockRange ?? DEFAULT_BLOCK_RANGE;

// check wether we should use cached leashes
// check whether we should use cached leashes
if (overrides?.nonce === undefined && overrides?.block === undefined) {
if (!signer.provider)
throw new Error(
Expand Down
1 change: 0 additions & 1 deletion examples/hardhat/scripts/run-vigil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async function main() {
await generateTraffic(10);
}

await generateTraffic(10);
await new Promise((resolve) => setTimeout(resolve, 30_000));
console.log('Checking the secret again');
await (await vigil.revealSecret(0)).wait(); // Reveal the secret.
Expand Down

0 comments on commit 132aed1

Please sign in to comment.