Skip to content

Commit

Permalink
Merge pull request #333 from EYBlockchain/westlad/ping-pong
Browse files Browse the repository at this point in the history
Westlad/ping pong
  • Loading branch information
Westlad authored Dec 14, 2021
2 parents d5be9f2 + 7c25213 commit fb2ad4f
Show file tree
Hide file tree
Showing 63 changed files with 14,957 additions and 731 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/check-PRs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
docker-compose build
./start-nightfall -g &> e2e-test.log &disown
- name: wait 1000s for Containers startup and setup completion
run: sleep 1000
- name: wait 1500s for Containers startup and setup completion
run: sleep 1500

- name: debug logs - after container startup
if: always()
Expand All @@ -56,7 +56,7 @@ jobs:
uses: actions/upload-artifact@master
with:
name: e2e-test-logs
path: ./e2e-test.log
path: ./e2e-test.log
ganache-test:
runs-on: ubuntu-18.04
steps:
Expand All @@ -70,8 +70,8 @@ jobs:
docker-compose build
./start-nightfall -g &> ganache-test.log &disown
- name: wait 1000s for Containers startup and setup completion
run: sleep 1000
- name: wait 1500s for Containers startup and setup completion
run: sleep 1500

- name: debug logs - after container startup
if: always()
Expand Down Expand Up @@ -110,8 +110,8 @@ jobs:
docker-compose build
./start-nightfall -wt -s &
- name: wait 1000s for Containers startup and setup completion
run: sleep 1000
- name: wait 1500s for Containers startup and setup completion
run: sleep 1500

- name: Retrieve Wallet test logs
run: docker logs $(docker ps -aqf "name=wallet-test") > wallet-test.log
Expand Down Expand Up @@ -148,8 +148,8 @@ jobs:
env:
TRANSACTIONS_PER_BLOCK: 32

- name: wait 1000s for Containers startup and setup completion
run: sleep 1000
- name: wait 1500s for Containers startup and setup completion
run: sleep 1500

- name: debug logs - after container startup
if: always()
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/publish-docker-app-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "Publish docker app images"
on:
push:
branches:
- master
- westlad/ping-pong

jobs:
release:
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1

- uses: codfish/semantic-release-action@master
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Login to docker registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $DOCKER_ACTOR --password-stdin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_ACTOR: ${{ secrets.DOCKER_ACTOR }}

- run: echo ${{ steps.semantic.outputs.release-version }}

- name: Docker push latest
run: |
docker build -t ghcr.io/eyblockchain/nightfall3-proposer . -f proposer.Dockerfile
docker push ghcr.io/eyblockchain/nightfall3-proposer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Docker push versioned
if: steps.semantic.outputs.new-release-published == 'true'
run: |
docker build -t ghcr.io/eyblockchain/nightfall3-proposer:$RELEASE_VERSION . -f proposer.Dockerfile
docker push ghcr.io/eyblockchain/nightfall3-proposer:$RELEASE_VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: echo ${{ steps.semantic.outputs.release-version }}

- name: Docker push latest
run: |
docker build -t ghcr.io/eyblockchain/nightfall3-user-local . -f user-local.Dockerfile
docker push ghcr.io/eyblockchain/nightfall3-user-local
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Docker push versioned
if: steps.semantic.outputs.new-release-published == 'true'
run: |
docker build -t ghcr.io/eyblockchain/nightfall3-user-local:$RELEASE_VERSION . -f user-local.Dockerfile
docker push ghcr.io/eyblockchain/nightfall3-user-local:$RELEASE_VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 26 additions & 9 deletions .github/workflows/publish-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- westlad/ping-pong

jobs:
release:
Expand All @@ -23,9 +24,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKER_ACTOR: ${{ secrets.DOCKER_ACTOR }}

- name: Build docker client image
run: docker build . -f client.Dockerfile

- run: echo ${{ steps.semantic.outputs.release-version }}

- name: Docker push version
Expand All @@ -36,8 +34,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build docker zokrates worker image
run: docker build . -f worker.Dockerfile
- name: Docker push latest
run: |
docker build -t ghcr.io/eyblockchain/nightfall3-client . -f client.Dockerfile
docker push ghcr.io/eyblockchain/nightfall3-client
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: echo ${{ steps.semantic.outputs.release-version }}

Expand All @@ -49,8 +51,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build docker deployer image
run: docker build . -f deployer.Dockerfile
- name: Docker push latest
run: |
docker build -t ghcr.io/eyblockchain/nightfall3-worker . -f worker.Dockerfile
docker push ghcr.io/eyblockchain/nightfall3-worker
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: echo ${{ steps.semantic.outputs.release-version }}

Expand All @@ -62,8 +68,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build docker optimist image
run: docker build . -f optimist.Dockerfile
- name: Docker push latest
run: |
docker build -t ghcr.io/eyblockchain/nightfall3-deployer . -f deployer.Dockerfile
docker push ghcr.io/eyblockchain/nightfall3-deployer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: echo ${{ steps.semantic.outputs.release-version }}

Expand All @@ -74,3 +84,10 @@ jobs:
docker push ghcr.io/eyblockchain/nightfall3-optimist:$RELEASE_VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Docker push latest
run: |
docker build -t ghcr.io/eyblockchain/nightfall3-optimist . -f optimist.Dockerfile
docker push ghcr.io/eyblockchain/nightfall3-optimist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 6 additions & 5 deletions cli/lib/nf3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ class Nf3 {
// if we don't have a nonce, we must get one from the ethereum client
if (!this.nonce) this.nonce = await this.web3.eth.getTransactionCount(this.ethereumAddress);

let gasPrice = 10000000000;
let gasPrice = 20000000000;
const gas = (await this.web3.eth.getBlock('latest')).gasLimit;
const blockGasPrice = Number(await this.web3.eth.getGasPrice());
const blockGasPrice = 2 * Number(await this.web3.eth.getGasPrice());
if (blockGasPrice > gasPrice) gasPrice = blockGasPrice;

tx = {
Expand Down Expand Up @@ -249,8 +249,9 @@ class Nf3 {
@returns {Promise} Resolves into the Ethereum transaction receipt.
*/
async deposit(ercAddress, tokenType, value, tokenId, fee = this.defaultFee) {
let txDataToSign;
try {
await approve(
txDataToSign = await approve(
ercAddress,
this.ethereumAddress,
this.shieldContractAddress,
Expand All @@ -261,7 +262,7 @@ class Nf3 {
} catch (err) {
throw new Error(err);
}

if (txDataToSign) await this.submitTransaction(txDataToSign, ercAddress, 0);
const res = await axios.post(`${this.clientBaseUrl}/deposit`, {
ercAddress,
tokenId,
Expand Down Expand Up @@ -753,7 +754,7 @@ class Nf3 {
Set a Web3 Provider URL
*/
setWeb3Provider() {
this.web3 = new Web3(this.web3WsUrl);
this.web3 = new Web3(this.web3WsUrl, { transactionBlockTimeout: 200 }); // set a longer timeout
if (typeof window !== 'undefined') {
if (window.ethereum && this.ethereumSigningKey === '') {
this.web3 = new Web3(window.ethereum);
Expand Down
21 changes: 12 additions & 9 deletions cli/lib/tokens.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Sends an approve transaction to an ERC20/ERC721/ERC1155 contract for a certain a
* @param {string} ercAddress - ERC contract address
* @param {string} ownerAddress - The Ethereum address of the transaction sender
* @param {string} spenderAddress - The Ethereum address of the approved entity
* @param {string} tokenType - Type of token
* @param {string} tokenType - Type of token
* @param {string} value - Amount of tokens to be approved (in Wei)
* @param {object} provider - web3 provider
* @returns {Promise} transaction
Expand All @@ -22,19 +22,22 @@ async function approve(ercAddress, ownerAddress, spenderAddress, tokenType, valu
const allowance = await ercContract.methods.allowance(ownerAddress, spenderAddress).call();
const allowanceBN = new Web3.utils.BN(allowance);
const valueBN = new Web3.utils.BN(value);

if (allowanceBN.lt(valueBN)) {
return ercContract.methods
if (process.env.USER_ETHEREUM_SIGNING_KEY)
return ercContract.methods.approve(spenderAddress, APPROVE_AMOUNT).encodeABI();
await ercContract.methods
.approve(spenderAddress, APPROVE_AMOUNT)
.send({ from: ownerAddress });
}
return Promise.resolve();
return Promise.resolve(false);
}

case TOKEN_TYPE.ERC721:
case TOKEN_TYPE.ERC1155: {
if (!(await ercContract.methods.isApprovedForAll(ownerAddress, spenderAddress).call())) {
return ercContract.methods
if (process.env.USER_ETHEREUM_SIGNING_KEY)
return ercContract.methods.setApprovalForAll(spenderAddress, true).encodeABI();
await ercContract.methods
.setApprovalForAll(spenderAddress, true)
.send({ from: ownerAddress });
}
Expand All @@ -44,15 +47,15 @@ async function approve(ercAddress, ownerAddress, spenderAddress, tokenType, valu
default:
throw new Error('Unknown token type', tokenType);
}
return Promise.resolve();
return Promise.resolve(false);
}

/**
Get decimals configured in ERC token
* @param {string} ercAddress - ERC contract address
* @param {string} tokenType - Type of token
* @param {string} tokenType - Type of token
* @param {object} provider - web3 provider
* @returns {Number} decimals
* @returns {Number} decimals
*/
async function getDecimals(ercAddress, tokenType, provider) {
const abi = getAbi(tokenType);
Expand All @@ -79,7 +82,7 @@ Get Information of ERC token in ethereum address. Default is in Wei
* @param {object} provider - web3 provider
* @param {object} options - different options for tokens. For ERC20, toEth is boolean
* to return the balance as Ether. For ERC1155, tokenId is required to get balance
* of specific token Id
* of specific token Id
* @returns {Object} {balance, decimals, tokenType, details}
*/
async function getERCInfo(ercAddress, ethereumAddress, provider, options) {
Expand Down
9 changes: 1 addition & 8 deletions cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"clear": "^0.1.0",
"cli-table": "^0.3.6",
"commander": "^8.2.0",
"config": "^3.3.6",
"figlet": "^1.5.2",
"inquirer": "^8.1.4",
"web3": "^1.5.2",
Expand Down
1 change: 0 additions & 1 deletion cli/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ async function askQuestions(nf3) {
Simple function to print out the balances object
*/
function printBalances(balances) {
console.log('BALANCES', balances);
if (Object.keys(balances).length === 0) {
console.log('You have no balances yet - try depositing some tokens into Layer 2 from Layer 1');
return;
Expand Down
21 changes: 21 additions & 0 deletions common-files/utils/crypto/eth-keys.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint import/no-extraneous-dependencies: "off" */
/**
utility to generate some ethereum private keys and addresses
*/
import Web3 from 'web3';
import rand from './crypto-random.mjs';

const web3 = new Web3();
async function printKeys() {
const privateKeys = [];
for (let i = 0; i < 10; i++) {
privateKeys.push(rand(32));
}
const addressPromises = privateKeys.map(async pk =>
web3.eth.accounts.privateKeyToAccount((await pk).hex(32), false),
);
const addresses = await Promise.all(addressPromises);
addresses.map(a => console.log('Private Key', a.privateKey, 'Address', a.address));
}

printKeys();
36 changes: 33 additions & 3 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,43 @@ module.exports = {
process.env.BLOCKCHAIN_URL ||
`ws://${process.env.BLOCKCHAIN_WS_HOST}:${process.env.BLOCKCHAIN_PORT}`,
USE_INFURA: process.env.USE_INFURA === 'true',
ETH_PRIVATE_KEY: process.env.ETH_PRIVATE_KEY,
ETH_PRIVATE_KEY: process.env.ETH_PRIVATE_KEY, // owner's/deployer's private key
ETH_ADDRESS: process.env.ETH_ADDRESS,
OPTIMIST_HOST: process.env.OPTIMIST_HOST || 'optimist',
OPTIMIST_PORT: process.env.OPTIMIST_PORT || 80,
clientBaseUrl: `http://${process.env.CLIENT_HOST}:${process.env.CLIENT_PORT}`,
optimistBaseUrl: `http://${process.env.OPTIMIST_HOST}:${process.env.OPTIMIST_HTTP_PORT}`,
optimistWsUrl: `ws://${process.env.OPTIMIST_HOST}:${process.env.OPTIMIST_WS_PORT}`,
web3WsUrl: `ws://${process.env.BLOCKCHAIN_WS_HOST}:${process.env.BLOCKCHAIN_PORT}`,
userEthereumSigningKey:
process.env.USER_ETHEREUM_SIGNING_KEY ||
'0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69e', // if changed, change associated userEthereumAddresses
userAddress: process.env.USER_ADDRESS,
UserEthereumAddresses: process.env.USER_ETHEREUM_ADDRESSES
? process.env.USER_ETHEREUM_ADDRESSES.split(',')
: [
'0x9c8b2276d490141ae1440da660e470e7c0349c63',
// '0x4ca4902a6f456b488947074ad4140317c7e21996', // 0xb0fa8745bd6e77a67ec6a27e701971d659937140cc3159d9f85210da3444eb45
// '0xfCb059A4dB5B961d3e48706fAC91a55Bad0035C9', // 0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb
],
zkpMnemonic:
process.env.ZKP_MNEMONIC ||
'hurt labor ketchup seven scan swap dirt brown brush path goat together',
proposerEthereumSigningKey:
process.env.PROPOSER_ETHEREUM_SIGNING_KEY ||
'0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d',
user1Pkd: process.env.RECIPIENT_PKD || [
'0x193a37cd7973373aceae05d133f3d69ab6e7ef2f4321461173871ec7611244e2',
'0x27234a8721e73c9aa160154ee63d2470101fc5fd841221eeb675a91ec2d66e78',
],
user2Pkd: process.env.RECIPIENT_PKD || [
'0x105651c0c5bb97582b3270e0f5a07ca81410ffd1920e86697efddaec03dccef8',
'0x1ac3b61ecba1448e697b23d37efe290fb86554b2f905aaca3a6df59805eca366',
],
WEB3_OPTIONS: {
gas: process.env.GAS || 1000000,
gas: process.env.GAS || 8000000,
gasPrice: process.env.GAS_PRICE || '20000000000',
from: process.env.FROM_ADDRESS || undefined,
from: process.env.FROM_ADDRESS || process.env.ETH_ADDRESS,
},
WEB3_PROVIDER_OPTIONS: {
clientConfig: {
Expand Down
Loading

0 comments on commit fb2ad4f

Please sign in to comment.