icn

package module
v0.0.0-...-d896040 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2018 License: GPL-3.0 Imports: 15 Imported by: 0

README

PoA Interchain Node Build Status

The PoA Interchain Node allows ethereum users to transfer funds between a main chain and a PoA side chain using multisig wallets.

Dependencies

  • solc
  • abigen
  • go
Dependencies of the development environment:
  • geth
  • bootnode
  • eth-contract-address
GOPATH

In your .bashrc:

export GOPATH="$HOME/go"
export PATH="$GOPATH/bin:$PATH"
Setup dependencies on OSX:
brew tap ethereum/ethereum
brew install ethereum
brew install solidity
go get github.com/kivutar/eth-contract-address
go install github.com/kivutar/eth-contract-address

abigen is supposed to be provided by the ethereum brew package on OSX. For some reasons, the installation of abigen doesn't always happen. (But it does install properly in Travis CI) You may have to build it from source:

go get github.com/ethereum/go-ethereum
cd $GOPATH/src/github.com/ethereum/go-ethereum/cmd/abigen/
go build
sudo cp abigen /usr/local/bin/abigen

Getting the source code

go get github.com/WeTrustPlatform/poa-interchain-node

But as the repo is still private, you will have to clone the repo directly in your go path:

mkdir -p $GOPATH/src/github.com/WeTrustPlatform/
cd $GOPATH/src/github.com/WeTrustPlatform/
git clone --recurse-submodules [email protected]:WeTrustPlatform/poa-interchain-node.git
cd poa-interchain-node
go generate ./...
go get -t -v ./...

Run the test suite

go test -cover -v ./...

Run the development environment

The interchain node comes with a helper in the form of a Makefile. This Makefile is not required to build the interchain node and use it. It is there to test the interchain node with the real geth. It will setup 3 instances of geth, 2 chains, and a few test accounts.

If you don't need to test the interchain node on geth, please skip all of the following steps and rely on the test suite only.

In 3 separate terminals:

cd dev/
make run_mainchain
make run_sidechain
make run_sidechain2

Wait 10 seconds between each call

Deploy the multisig wallet on both chains

make mainchain_wallet sidechain_wallet

Sending ether to arbitrary addresses offchain

Our multisig wallets have a function called deposit which allows you to transfer ether from your address on the chain A to a receiver on the chain B.

Instead of paying to the wallet address, you call the deposit method using the geth console or our utility program icn-deposit.go:

go run ../cmd/icn-deposit/main.go --mainchain --keyjson=mainchain/keystore/<your_key_json> --password="dummy" --endpoint=mainchain/geth.ipc --wallet=`cat mainchain/wallet` --receiver=`cat sidechain/sealer` --value="25000000000000000000"

Usage:

Usage:
  main [OPTIONS]

Application Options:
  -m, --mainchain  Target the main chain wallet
  -s, --sidechain  Target the side chain wallet
  -k, --keyjson=   Path to the JSON private key file of the sealer
  -p, --password=  Passphrase needed to unlock the sealer's JSON key
  -e, --endpoint=  URL or path of the origin chain endpoint
  -w, --wallet=    Ethereum address of the multisig wallet on the origin chain
  -r, --receiver=  Ethereum address of the receiver on the target chain
  -v, --value=     Value (wei) to transfer to the receiver

Help Options:
  -h, --help       Show this help message

The interchain node will notice your call and mirror the transaction on the other chain.

Run the interchain node

For each sealer, run the interchain node:

go run ../cmd/icn/main.go -k sidechain/keystore/<sealer1_key_json> --mainchainendpoint=mainchain/geth.ipc --sidechainendpoint=sidechain/geth.ipc -p dummy --mainchainwallet=`cat mainchain/wallet` --sidechainwallet=`cat sidechain/wallet` -d=sealer1db

go run ../cmd/icn/main.go -k sidechain2/keystore/<sealer2_key_json> --mainchainendpoint=mainchain/geth.ipc --sidechainendpoint=sidechain2/geth.ipc -p dummy --mainchainwallet=`cat mainchain/wallet` --sidechainwallet=`cat sidechain/wallet` -d=sealer2db
Usage:
  main [OPTIONS]

Application Options:
  -m, --mainchain          Watch the main chain
  -s, --sidechain          Watch the side chain
  -k, --keyjson=           Path to the JSON private key file of the sealer
  -p, --password=          Passphrase needed to unlock the sealer's JSON key
      --mainchainendpoint= URL or path of the main chain endpoint
      --sidechainendpoint= URL or path of the side chain endpoint
      --mainchainwallet=   Ethereum address of the multisig wallet on the main chain
      --sidechainwallet=   Ethereum address of the multisig wallet on the side chain

Help Options:
  -h, --help               Show this help message

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EndBlock

func EndBlock(start uint64, nblocks uint64) *uint64

EndBlock calculates the last block to process

func GetLastProcessedBlock

func GetLastProcessedBlock(dbPath string, eventType string) uint64

GetLastProcessedBlock returns the last processed block number from a file

func HasEnoughSignaturesMC

func HasEnoughSignaturesMC(ctx context.Context, sc *sidechain.SideChain, sealerAddr common.Address, txHash common.Hash) (bool, error)

HasEnoughSignaturesMC checks if a transaction got enough signature to be withdrawn on the main chain

func MsgHash

func MsgHash(
	contractAddress common.Address,
	txHash common.Hash,
	toAddress common.Address,
	value *big.Int,
	data []byte,
	version uint8) common.Hash

MsgHash returns the sha3 sum of 0x19, contractAddress, txHash, toAddress, value, data and version

func ParseSignature

func ParseSignature(sig []byte) (v uint8, r, s common.Hash)

ParseSignature parses a ECDSA signature and returns v, r, s

func PersistLastBlock

func PersistLastBlock(dbPath string, eventType string, blockNumber uint64)

PersistLastBlock saves the last processed block to a file

func ProcessMCDeposits

func ProcessMCDeposits(ctx context.Context, auth *bind.TransactOpts,
	mc *mainchain.MainChain, sc *sidechain.SideChain,
	dbPath string, start uint64, end *uint64, wg *sync.WaitGroup)

ProcessMCDeposits watches the main chain and for each Deposit calls SubmitTransactionSC on the side chain

func ProcessSCDeposits

func ProcessSCDeposits(ctx context.Context, auth *bind.TransactOpts,
	mc *mainchain.MainChain, sc *sidechain.SideChain,
	addr common.Address, key *ecdsa.PrivateKey,
	dbPath string, start uint64, end *uint64, wg *sync.WaitGroup)

ProcessSCDeposits watches the side chain and for each Deposit calls SubmitSignatureMC on the side chain

func ProcessSCSignatureAdded

func ProcessSCSignatureAdded(ctx context.Context, auth *bind.TransactOpts,
	mc *mainchain.MainChain, sc *sidechain.SideChain,
	dbPath string, start uint64, end *uint64, wg *sync.WaitGroup)

ProcessSCSignatureAdded watches the side chain and for each SignatureAdded calls SubmitTransaction on the main chain

func Sign

func Sign(msgHash common.Hash, key *ecdsa.PrivateKey,
) (v uint8, r, s common.Hash, err error)

Sign signs a msgHash and return the v r s signature

func SubmitSignatureMC

func SubmitSignatureMC(
	ctx context.Context,
	sideChainWalletAddress common.Address,
	auth *bind.TransactOpts,
	sc *sidechain.SideChain,
	event *sidechain.SideChainDeposit,
	key *ecdsa.PrivateKey,
) (*types.Transaction, error)

SubmitSignatureMC submits a signature on the sidechain that will be later checked on the mainchain

Types

This section is empty.

Directories

Path Synopsis
cmd
icn command
icn-deploy command
Command line utility to deploy the multisig wallets
Command line utility to deploy the multisig wallets
icn-deposit command
Utility to perform a transfer to another address on the other chain using the wallet
Utility to perform a transfer to another address on the other chain using the wallet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL