Assumes nvm in use 10 LTS, this is because the node installs will fail if using the system node.
Additionally requires ganache-ui, sequel pro, docker, and a browser running metamask.
-
Boot up new instance of ganache ui, make sure port is set to 8545, cancel and restart if necessary
-
Open up browser with metamask, switch to localhost 8545, import the first account by private key, confrim 100ETH
-
Open up a terminal and setup project sandbox
cd ~ && export XYO_HOME=`pwd`/xyo && echo "XYO_HOME set to $XYO_HOME"
- Setup archivist
export ARCHIVIST_BRANCH=develop && git clone -b $ARCHIVIST_BRANCH https://github.com/XYOracleNetwork/app-archivist-nodejs.git archivist
cd $XYO_HOME/archivist && mkdir logs && mkdir archivist-db
Set up database credentials
export MYSQL_USER=admin && export MYSQL_PASSWORD=password
Start MySQL service
docker run \
--name XyoDb \
-d \
-p 3306:3306 \
-e MYSQL_USER=$MYSQL_USER \
-e MYSQL_PASSWORD=$MYSQL_PASSWORD \
-e MYSQL_DATABASE=Xyo \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
mysql:5.7.24 --sql_mode=NO_ENGINE_SUBSTITUTION
Pick a name for your node
export ARCHIVIST_NODE_NAME=my-archivist
Figure out ip address and set it
export MY_IP=`ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'` && echo "My ip is $MY_IP
Start the archivist
NODE_ENV=develop \
NODE_NAME=$ARCHIVIST_NODE_NAME \
IP_OVERRIDE=$MY_IP \
SQL__HOST=127.0.0.1 \
SQL__USER=$MYSQL_USER \
SQL__PASSWORD=$MYSQL_PASSWORD \
SQL__DATABASE=Xyo \
SQL__PORT=3306 \
nohup node packages/app-archivist/dist/index.js &
Tail the logs, you can see a genesis block was created
tail -f -n 1000 nohup.out
- Diviner set up
export DIVINER_BRANCH=develop
cd $XYO_HOME && git clone -b $DIVINER_BRANCH https://github.com/XYOracleNetwork/api-diviner-nodejs.git diviner
Project set up
cd $XYO_HOME/diviner && mkdir logs && mkdir diviner-db && yarn clean && yarn install && yarn build
- ipfs set up
mkdir -p $XYO_HOME/ipfs/staging && \
mkdir -p $XYO_HOME/ipfs/data && \
export ipfs_staging=$XYO_HOME/ipfs/staging && \
export ipfs_data=$XYO_HOME/ipfs/data
Start docker ipfs service
docker run \
-d \
--name ipfs_host \
-v $ipfs_staging:/export \
-v $ipfs_data:/data/ipfs \
-p 4001:4001 \
-p 127.0.0.1:8080:8080 \
-p 127.0.0.1:5001:5001 \
ipfs/go-ipfs:latest
Cors config
docker exec ipfs_host ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
docker exec ipfs_host ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
Restart ipfs service
docker restart ipfs_host
ipfs add file
curl 'https://ipfs.io/ipfs/QmeFQ55jVbtuVoFYXJdZWKoWMjjs9DZ9teCQhrhTLofGP2' > $ipfs_staging/XyoStakedConsensus.json && \
docker exec ipfs_host ipfs add -r /export/XyoStakedConsensus.json
Set environment variable for diviner eth address, confirm is first account in ganache
export ABOUT__ETH_ADDRESS=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' 127.0.0.1:8545 | python -c "import sys, json; print json.load(sys.stdin)['result'][0]"` && echo "Diviner ethereum address is $ABOUT__ETH_ADDRESS"
Build from source the PayOnDelivery contracts
cd $XYO_HOME && git clone https://github.com/XYOracleNetwork/demo-payondelivery-solidity.git payondelivery && cd $XYO_HOME/payondelivery && yarn
Optionally install dapploy if is not already installed
yarn global add tool-dapploy-nodejs
Deploy contracts
dapploy
Confirm in ganache-ui that transactions have contracts have been created in transactions tab. You will also see the fist account have slightly less ethereum for the cost of gas of deploying contract
Copy contracts artifacts into ipfs
cp -r build/contracts $ipfs_staging && docker exec ipfs_host ipfs add -r /export/contracts
This will output something like added Qm...
contracts.
You should be able to open a browser and view the contracts folder at 127.0.0.1:8080/ipfs/Qm...
Open a browser with metamask installed and go to https://dapper.layerone.co/
Clear application cache through inspect-tools -> Application -> clear storage -> clear site data then refresh page
Then connect wallet with the account that we added earlier.
Go to setting by clicking cog wheel
Set ipfs config to
host: localhost port: 8080 protocol: http
Then copy the contracts ipfs hash from earlier and click add abi
You should be able to select a contract from left dropdown, PayOnDelivery
and the bottom drop down and the contract address
If you select the owner()
button and execute it should display your public key and if you go to question and add a parameter of 0
and error because there are no questions yet, so lets create some data to ask questions about first.
Create mock data
cd $XYO_HOME/archivist && node packages/data-generator/dist/index.js --host=127.0.0.1 --user=$MYSQL_USER --password=$MYSQL_PASSWORD --database=Xyo --port=3306
open sequel pro
set database credentials
host: 127.0.0.1 username: admin password: password port: 3306
Select query tab and query
SELECT
obp.originBlockId,
GROUP_CONCAT(pk.key SEPARATOR ", "),
ob.signedHash
FROM OriginBlockParties obp
JOIN OriginBlocks ob on ob.id = obp.originBlockId
JOIN KeySignatures ks on obp.id = ks.originBlockPartyId
JOIN PublicKeys pk on pk.id = ks.publicKeyId
GROUP BY obp.originBlockId
HAVING COUNT(obp.originBlockId) > 1
************************************* Skip this *************************************************************
Note, this same data is available via a graphql interface at 127.0.0.1:11001 with the query
query {
blockList(limit: 10, cursor: null) {
items {
publicKeys {
array {
value
}
}
}
}
}
You would have to find a result in the array that has two array
values for the publicKeys key/value pair
************************************* End Skip *************************************************************
Click run current
to view results.
The results showing are all the bound witness interactions in the system.
Select the first row, second column and copy the the items as the itemA and itemB into the escrowPayment
dapper view.
For the beneficiary
input, put the last ganache account public key
For marker put 0
and for Value to transfer
do 10000000000000000000
(10Eth). Execute contract with metamask. Confirm in ganache-ui that 10Eth is in escrow for the first address.
make note of the address from dapper.layerone.co for PayOnDelivery contract Deployments -> address section. It should with 0x
Go back to terminal and run
export ETHEREUM_CONTRACTS__PAY_ON_DELIVERY__ADDRESS={CONTRACT_ADDRESS_ABOVE_REPLACE_ME}
Change directory to diviner
cd $XYO_HOME/diviner
Start diviner. Once the diviner is started it will find the first question in the smart contract, ask the archivist for data about the publicKeys (itemA, itemB), the archivist provides an answer and the diviner answer the SmartContract with results in the beneficiary getting 10Eth out of escrow. You can verify this by going to ganache-ui and looking at the Account Balances.
ABOUT__URL=$MY_IP \
ABOUT__SEEDS__ARCHIVISTS=http://127.0.0.1:11001 \
IPFS__HOST=127.0.0.1 \
ETHEREUM_CONTRACTS__PAY_ON_DELIVERY__ADDRESS=$ETHEREUM_CONTRACTS__PAY_ON_DELIVERY__ADDRESS \
WEB3__HOST=http://127.0.0.1:8545 \
nohup node packages/app-diviner/dist/index.js &
**** Tear Down ****
Stop and remove all docker containers
docker stop ipfs_host && docker rm ipfs_host && docker stop XyoDb && docker rm XyoDb && docker system prune -a
rm -rf $XYO_HOME
Kill diviner and archivist processes
ps -A | grep archivist # Then kill process id
ps -A | grep diviner # Then kill process id