Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions salad/operator/config/compose_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"ENG_NODE_PORT": "3346",
"MONGO_URL": "mongodb://mongo:27017",
"DB_NAME": "salad",
"FAUCET_URL": "http://contract:8001",
"OPERATOR_ETH_PRIVATE_KEY": null,
"SECRET_CONTRACT_BUILD_FOLDER": "..",
"SALAD_SMART_CONTRACT_ADDRESS": "",
Expand Down
3 changes: 2 additions & 1 deletion salad/operator/config/k8s_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"ENG_NODE_PORT": "3346",
"MONGO_URL": "mongodb://mongo:27017",
"DB_NAME": "salad",
"FAUCET_URL": "http://contract-service:8001",
"OPERATOR_ETH_PRIVATE_KEY": null,
"SECRET_CONTRACT_BUILD_FOLDER": "..",
"SALAD_SMART_CONTRACT_ADDRESS": "",
"SALAD_SECRET_CONTRACT_ADDRESS": "",
"KEY_MANAGEMENT_DISCOVERY": "unused",
"LOG_LEVEL": "debug"
}
}
3 changes: 2 additions & 1 deletion salad/operator/scripts/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def main():
'SALAD_SMART_CONTRACT_ADDRESS': 'SALAD_SMART_CONTRACT_ADDRESS',
'SALAD_SECRET_CONTRACT_ADDRESS': 'SALAD_SECRET_CONTRACT_ADDRESS',
'NETWORK_ID': 'NETWORK_ID',
'FAUCET_URL': 'FAUCET_URL'
}.items():
envs[env_var] = config[config_var]
envs[env_var] = config.get(config_var)

envs['ENIGMA_CONTRACT_ADDRESS'] = enigma_contract_address
envs['ENIGMA_TOKEN_CONTRACT_ADDRESS'] = enigma_token_contract_address
Expand Down
12 changes: 12 additions & 0 deletions salad/operator/scripts/create_account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env node

const Web3 = require('web3');

function main() {
const web3 = new Web3();
web3.eth.accounts.wallet.create(1);
let account = web3.eth.accounts.wallet[0];
console.log(account.address, account.privateKey);
}

main();
28 changes: 28 additions & 0 deletions salad/operator/scripts/distribute_funds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3

import sys
from enigma_docker_common.faucet_api import request_coins
from enigma_docker_common.config import Config
from enigma_docker_common.logger import get_logger

logger = get_logger('operator-startup')

try:
config = Config(required=['FAUCET_URL'])
except (ValueError, IOError) as e:
logger.critical(f'encountered unexpected error while configuring the operator: {e!r}')
raise


def main():
addresses = sys.argv[1:]
faucet_url = config['FAUCET_URL']
for address in addresses:
logger.info(f'distributing ether to {address}')
request_coins(faucet_url, address, 'ether')
logger.info(f'distributing eng to {address}')
request_coins(faucet_url, address, 'eng')


if __name__ == '__main__':
main()
13 changes: 13 additions & 0 deletions salad/operator/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ if ! ./scripts/take_salad_contract_addresses_from_environment.js; then
echo 'Running deployment...'
ENV=$(echo "$ENIGMA_ENV" | tr '[:upper:]' '[:lower:]')
npx truffle migrate --network $ENV
./scripts/wait_for_epoch_transition.js
echo 'Done deployment!'
fi

# If the operator's private key has not been supplied externally, provide it here.
if [[ -z "$OPERATOR_ETH_PRIVATE_KEY" ]]; then
echo 'generating account for operator'
ACCOUNT_1="$(./scripts/create_account.js)"

ADDRESS_1="$(echo "$ACCOUNT_1" | cut -d' ' -f1)"
PRIVATE_KEY_1="$(echo "$ACCOUNT_1" | cut -d' ' -f2)"
export OPERATOR_ETH_PRIVATE_KEY="$PRIVATE_KEY_1"

./scripts/distribute_funds.py "$ADDRESS_1"
fi

node ./operator/src/server.js -t
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ async function main() {
await store.insertSmartContractAddress(process.env.SALAD_SMART_CONTRACT_ADDRESS);
await store.insertSecretContractAddress(process.env.SALAD_SECRET_CONTRACT_ADDRESS);
} catch (e) {
log.error('Error while taking contract addresses from env', e);
log.info('Error while taking contract addresses from env', e);
} finally {
await store.closeAsync();
}
}

main().catch(err => { log.error(err); process.exit(1) });
main().catch(err => { log.info(err); process.exit(1) });
41 changes: 41 additions & 0 deletions salad/operator/scripts/wait_for_epoch_transition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node

require('dotenv').config();
const Web3 = require('web3');
const {Enigma} = require('enigma-js/node');
Comment thread
reuvenpo marked this conversation as resolved.

const main = async () => {
const provider = new Web3.providers.WebsocketProvider(`ws://${process.env.ETH_HOST}:${process.env.ETH_PORT}`);
Comment thread
Cashmaney marked this conversation as resolved.
const web3 = new Web3(provider);

let enigmaHost = process.env.ENIGMA_HOST || 'localhost';
let enigmaPort = process.env.ENIGMA_PORT || '3333';
const enigmaAddr = process.env.ENIGMA_CONTRACT_ADDRESS;
const enigmaTokenAddr = process.env.ENIGMA_TOKEN_CONTRACT_ADDRESS;

const enigma = new Enigma(
web3,
enigmaAddr,
enigmaTokenAddr,
'http://' + enigmaHost + ':' + enigmaPort,
{
gas: 4712388,
from: web3.eth.accounts[0],
Comment thread
Cashmaney marked this conversation as resolved.
},
);

const enigmaContract = enigma.enigmaContract;
console.log('Waiting for an epoch to pass after the contract deployment');
await new Promise(resolve =>
enigmaContract.events.WorkersParameterized({})
.once('data', data => {
console.log(`got data ${JSON.stringify(data)}`);
resolve(data);
})
);
console.log('an epoch has passed');
await web3.currentProvider.disconnect();
console.log('provider disconnected');
};

main().catch(err => { console.log(err); process.exit(1) });