Skip to content

Commit bf0bc1f

Browse files
committed
add ability to create config and run node
1 parent bd0a058 commit bf0bc1f

File tree

7 files changed

+57
-33
lines changed

7 files changed

+57
-33
lines changed

Makefile

+17-1
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,24 @@ build-binary: install-deps
8787
fi
8888
@echo "Built and packed into `ls *tar.gz`"
8989

90-
start-local-env:
90+
start-local-env: clean
9191
@FORCE_MIGRATE=true RUN_TESTS="false" ./build/scripts/test_wrapper.sh
9292

9393
stop-local-env:
9494
@CLEANUP="true" ./build/scripts/test_wrapper.sh
95+
96+
ethAccountKeyPath?=./build/scripts/test-dependencies/test-ethereum/migrateAccount.json
97+
ethAccountKey?=$(shell cat ${ethAccountKeyPath})
98+
targetDir?=${HOME}/centrifuge/testing
99+
identityFactory:=$(shell < ./localAddresses grep "identityFactory" | awk '{print $$2}' | tr -d '\n')
100+
start-local-node:
101+
@echo "Creating local test config for the Node at ${targetDir}"
102+
@rm -rf "${targetDir}"
103+
@go build -ldflags "-X github.com/centrifuge/go-centrifuge/version.gitCommit=`git rev-parse HEAD`" ./cmd/centrifuge/...
104+
@./centrifuge createconfig --accountkeypath="${ethAccountKeyPath}" \
105+
--ethnodeurl="http://localhost:9545" --identityFactory=${identityFactory} --targetdir="${targetDir}" \
106+
--centchainaddr="5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" \
107+
--centchainid="0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" \
108+
--centchainsecret="//Alice" --centchainurl="ws://localhost:9944" --network=testing &> /dev/null
109+
@echo "Starting centrifuge node..."
110+
@CENT_ETHEREUM_ACCOUNTS_MAIN_KEY='${ethAccountKey}' CENT_ETHEREUM_ACCOUNTS_MAIN_PASSWORD="" ./centrifuge run -c "${targetDir}"/config.yaml

README.md

+14-19
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,25 @@ To force ethereum smart contracts to be deployed again: `FORCE_MIGRATE='true' te
3232

3333
Note: `unit` tests doesn't require any smart contract deployments and when run with only `unit` flavour, smart contracts are not deployed.
3434

35+
## Spin-up local environment:
36+
To spin-up local environment, run `make start-local-env`
37+
This command will start Centrifuge chain node, Geth node, and bridge using docker.
38+
39+
## Create config file and Start centrifuge node locally:
40+
To start centrifuge node locally, follow the steps below:
41+
- Start the local test environment
42+
- run `make start-local-node`
43+
This will start a local centrifuge node. It will override any previous configs that were created.
44+
45+
## Spin-down local environment:
46+
To spin-down local environment, run `make stop-local-env`
47+
This command will stop Centrifuge chain node, Geth node, and bridge if running.
48+
3549
## Installation
3650
To install, run `make install` will compile project to binary `centrifuge` and be placed under `GOBIN`.
3751

3852
Ensure `GOBIN` is under `PATH` to call the binary globally.
3953

40-
## Spin-up local test environment:
41-
For development, we use Docker Compose locally
42-
43-
### Centrifuge Chain
44-
Local Centrifuge Chain comes with a set of preconfigured accounts to be used.
45-
46-
Start local centrifuge chain via `./build/scripts/docker/run.sh ccdev`
47-
48-
For more info: https://github.com/centrifuge/centrifuge-chain
49-
50-
### Run a Geth node locally in dev mode
51-
52-
Start the local geth node via `./build/scripts/docker/run.sh dev`
53-
54-
By default, geth node uses:
55-
- ETH_DATADIR=${HOME}/Library/Ethereum
56-
- RPC_PORT=9545
57-
- WS_PORT=9546
58-
5954
## API definitions
6055
Node APIs are published to swagger hub.
6156
For the latest APIs, please see here: [APIs](https://app.swaggerhub.com/apis/centrifuge.io/cent-node/)

build/scripts/migrateDApp.sh

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ echo "Identity factory $IDENTITY_FACTORY"
5050
assetManagerAddr=$(< "$PARENT_DIR"/localAddresses grep "assetManager" | awk '{print $2}' | tr -d '\n')
5151
nftAddr=$(seth send --create out/AssetNFT.bin 'AssetNFT(address, address)' "$assetManagerAddr" "$IDENTITY_FACTORY")
5252
echo "genericNFT $nftAddr" >> "$PARENT_DIR"/localAddresses
53+
echo "identityFactory $IDENTITY_FACTORY" >> "$PARENT_DIR"/localAddresses
5354

5455
genericAddr=$(< "$PARENT_DIR"/localAddresses grep "genericAddr" | awk '{print $2}' | tr -d '\n')
5556
bridgeAddr=$(< "$PARENT_DIR"/localAddresses grep "bridgeAddr" | awk '{print $2}' | tr -d '\n')

build/scripts/test-dependencies/bridge/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ echo "MaxCount: $maxCount"
2020
count=0
2121
while true
2222
do
23-
started=$(docker logs bridge 2>&1 | grep 'Block not ready, will retry')
23+
started=$(docker logs bridge 2>&1 | grep 'Block not')
2424
if [ "$started" != "" ]; then
2525
echo "Bridge successfully started"
2626
break

cmd/centrifuge/create_config.go

+22-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"syscall"
77

88
"github.com/centrifuge/go-centrifuge/cmd"
9+
"github.com/centrifuge/go-centrifuge/config"
910
"github.com/mitchellh/go-homedir"
1011
"github.com/spf13/cobra"
1112
"golang.org/x/crypto/ssh/terminal"
@@ -16,6 +17,7 @@ var (
1617
apiPort, p2pPort int64
1718
bootstraps []string
1819
centChainURL, centChainID, centChainSecret, centChainAddress string
20+
identityFactoryAddr string
1921
)
2022

2123
func init() {
@@ -30,30 +32,38 @@ func init() {
3032
Short: "Configures Node",
3133
Long: ``,
3234
Run: func(c *cobra.Command, args []string) {
33-
_, err := fmt.Fprintln(os.Stderr, "Enter your Ethereum Account Password:")
34-
if err != nil {
35-
log.Fatal(err)
36-
}
35+
var contractAddrs *config.SmartContractAddresses
36+
var ethPassword string
37+
if network == "testing" {
38+
contractAddrs = &config.SmartContractAddresses{IdentityFactoryAddr: identityFactoryAddr}
39+
} else {
40+
_, err := fmt.Fprintln(os.Stderr, "Enter your Ethereum Account Password:")
41+
if err != nil {
42+
log.Fatal(err)
43+
}
3744

38-
pwd, err := terminal.ReadPassword(syscall.Stdin)
39-
if err != nil {
40-
// lets take empty password
41-
log.Error(err)
45+
pwd, err := terminal.ReadPassword(syscall.Stdin)
46+
if err != nil {
47+
// lets take empty password
48+
log.Error(err)
49+
}
50+
51+
ethPassword = string(pwd)
4252
}
4353

4454
err = cmd.CreateConfig(
4555
targetDataDir,
4656
ethNodeURL,
4757
accountKeyPath,
48-
string(pwd),
58+
ethPassword,
4959
network,
5060
apiHost,
5161
apiPort,
5262
p2pPort,
5363
bootstraps,
5464
false,
5565
"",
56-
nil,
66+
contractAddrs,
5767
"",
5868
centChainURL, centChainID, centChainSecret, centChainAddress)
5969
if err != nil {
@@ -81,5 +91,7 @@ func init() {
8191
createConfigCmd.Flags().StringVar(&centChainID, "centchainid", "", "Centrifuge Chain Account ID")
8292
createConfigCmd.Flags().StringVar(&centChainSecret, "centchainsecret", "", "Centrifuge Chain Secret URI")
8393
createConfigCmd.Flags().StringVar(&centChainAddress, "centchainaddr", "", "Centrifuge Chain ss58addr")
94+
createConfigCmd.Flags().StringVar(&identityFactoryAddr, "identityFactory", "",
95+
"Ethereum Identity factory address for testing network")
8496
rootCmd.AddCommand(createConfigCmd)
8597
}

migration/files/02AddPrefix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func AddPrefix02(db *leveldb.DB) error {
2727
v := new(value)
2828
err := json.Unmarshal(data, v)
2929
if err != nil {
30-
return err
30+
continue
3131
}
3232
prefix := []byte("document_")
3333
if strings.Contains(v.Type, "jobs.Job") {

migration/wrapper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (mr *Runner) RunMigrations(dbPath string) error {
4747
}
4848
sort.Strings(migrationList)
4949

50-
//For each of them, in order execute
50+
// For each of them, in order execute
5151
for _, k := range migrationList {
5252
start := time.Now()
5353

0 commit comments

Comments
 (0)