Skip to content

Commit

Permalink
Merge pull request #310 from MysteriumNetwork/feature/MYST-586-endpoi…
Browse files Browse the repository at this point in the history
…nt-with-identity-registration-status

Feature/myst 586 endpoint with identity registration status
  • Loading branch information
tadovas committed Aug 9, 2018
2 parents a85a494 + 9518824 commit b48aa38
Show file tree
Hide file tree
Showing 28 changed files with 1,859 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"a754f0d31411d88e46aed455fa79b9fced122497","crypto":{"cipher":"aes-128-ctr","ciphertext":"56c3a9b187b9acfe64d9d9ab2f0236f990f533f99ddb05cc0d5be9340f7fb755","cipherparams":{"iv":"fa76b9c835859593db14cd4820078b88"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"3dfdd74c4e7eb4d6ef3b449b836438f3082a34bd0c6dc82a85bde4f30421e1b9"},"mac":"97c1323a22cddb1dac9652a1b3b6b07706193a12cf056256dee963647686cde7"},"id":"965998e2-2a62-4aae-9b0d-b3a723b8d521","version":3}
93 changes: 93 additions & 0 deletions bin/localnet/deployer/deployer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2017 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package main

import (
"context"
"flag"
"fmt"
"github.com/MysteriumNetwork/payments/cli/helpers"
mysttoken "github.com/MysteriumNetwork/payments/mysttoken/generated"
promises "github.com/MysteriumNetwork/payments/promises/generated"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"math/big"
"os"
"time"
)

func main() {

keyStoreDir := flag.String("keystore.directory", "", "Directory of keystore")
etherAddress := flag.String("ether.address", "", "Account inside keystore to use for deployment")
etherPassphrase := flag.String("ether.passphrase", "", "Passphrase for account unlocking")
ethRPC := flag.String("geth.url", "", "RPC url of ethereum client")

flag.Parse()

ks := helpers.GetKeystore(*keyStoreDir)

acc, err := helpers.GetUnlockedAcc(*etherAddress, *etherPassphrase, ks)
checkError("Unlock acc", err)

transactor := helpers.CreateNewKeystoreTransactor(ks, acc)

client, synced, err := helpers.LookupBackend(*ethRPC)
checkError("Backend lookup", err)
<-synced

mystTokenAddress, tx, _, err := mysttoken.DeployMystToken(transactor, client)
checkError("Deploy token", err)
checkTxStatus(client, tx)
fmt.Println("Token: ", mystTokenAddress.String())

transactor.Nonce = big.NewInt(int64(tx.Nonce() + 1))
paymentsAddress, tx, _, err := promises.DeployIdentityPromises(transactor, client, mystTokenAddress, big.NewInt(100))
checkError("Deploy payments", err)
checkTxStatus(client, tx)

fmt.Println("Payments: ", paymentsAddress.String())
}

func checkError(context string, err error) {
if err != nil {
fmt.Println("Error at:", context, "value:", err.Error())
os.Exit(1)
}
}

func checkTxStatus(client *ethclient.Client, tx *types.Transaction) {

//wait for transaction to be mined at most 10 seconds
for i := 0; i < 10; i++ {
_, pending, err := client.TransactionByHash(context.Background(), tx.Hash())
checkError("Get tx by hash", err)
if pending {
time.Sleep(1 * time.Second)
} else {
break
}
}

receipt, err := client.TransactionReceipt(context.Background(), tx.Hash())
checkError("Fetch tx receipt", err)
if receipt.Status != 1 {
fmt.Println("Receipt status expected to be 1")
os.Exit(1)
}
}
35 changes: 35 additions & 0 deletions bin/localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,38 @@ services:
DB_PASSWORD: myst_api
depends_on:
- db

#private blockchain with single miner and single node
local-node:
image: mysteriumnetwork/geth:1.8.12
expose:
- 8545
volumes:
- geth-runtime:/ethereum/geth-runtime
- ./genesis.json:/ethereum/genesis.json
- ./node:/ethereum/keystore
- ./node_acc_password.txt:/ethereum/node_acc_password.txt
command: >
--syncmode 'full'
--port 30311
--rpc
--rpcaddr '0.0.0.0'
--rpcport 8545
--rpcapi personal,db,eth,net,web3,txpool,miner
--networkid 69
--gasprice '1'
--unlock '0xd9786b6ee6caf5cd0ef88301fc40de83bfac5594'
--password node_acc_password.txt
--rpcvhosts *
--rpccorsdomain *
--mine
#go runner to run go programs inside localnet (usefull for contract deployment or e2e test running)
go-runner:
image: golang:1.10
volumes:
- $GOPATH:/go
working_dir: /go/src/github.com/mysterium/node

volumes:
geth-runtime:
31 changes: 27 additions & 4 deletions bin/localnet/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,40 @@ setup () {
exit 1
fi

${dockerComposeCmd} up -d broker discovery
${dockerComposeCmd} run local-node init genesis.json
if [ ! $? -eq 0 ]; then
print_error "Starting built docker images failed"
print_error "Geth node initialization failed"
cleanup "$@"
exit 1
fi


${dockerComposeCmd} up -d broker discovery local-node
if [ ! $? -eq 0 ]; then
print_error "Error starting other services"
cleanup "$@"
exit 1
fi

#deploy MystToken and Payment contracts
echo "Deploying contracts..."
${dockerComposeCmd} run go-runner \
go run bin/localnet/deployer/*.go \
--keystore.directory=bin/localnet/account \
--ether.address=0xa754f0d31411d88e46aed455fa79b9fced122497 \
--ether.passphrase `cat bin/localnet/local_acc_password.txt` \
--geth.url=http://local-node:8545
if [ ! $? -eq 0 ]; then
print_error "Error deploying contracts"
cleanup "$@"
exit 1
fi

}

cleanup () {
setupDockerComposeCmd "$@"

echo "Cleaning up: $projectName"
${dockerComposeCmd} down --remove-orphans
}
${dockerComposeCmd} down --remove-orphans --volumes
}

0 comments on commit b48aa38

Please sign in to comment.