Skip to content
Permalink
Browse files

tomovalidator code

  • Loading branch information...
thanhson1085 committed Nov 11, 2018
1 parent 74f0b9a commit 93f0d6bfc11e5261a814753b39d982013bee6f48
Showing with 47 additions and 11 deletions.
  1. +1 −0 .gitignore
  2. +7 −0 keys.json
  3. BIN main
  4. +39 −11 main.go
@@ -0,0 +1 @@
.*.sw*
@@ -0,0 +1,7 @@
{
"owner": "d20f522d0828db540e402b06b29c4247b096737e6e6f6ee35204fe108330ed5c",
"masternodes": [
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291",
"09991738687c1ae0f6c13c54d395d2df8d2087ffce8ae9011d553cc40f0913f6"
]
}
BIN +13.6 MB main
Binary file not shown.
50 main.go
@@ -3,12 +3,15 @@ package main
import (
"bytes"
"fmt"
"os"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"

"context"
"encoding/json"
"io/ioutil"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -18,20 +21,45 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)

type Keys struct {
Owner string `json:"owner"`
Masternodes []string `json:"masternodes"`
}

func main() {
fmt.Println("test")
// Validator Smart Contract Code
pKey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr := crypto.PubkeyToAddress(pKey.PublicKey)
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(pKey)
jsonFile, err := os.Open("keys.json")
if err != nil {
fmt.Println(err)
}
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)

addr = crypto.PubkeyToAddress(pKey.PublicKey)
signers := []common.Address{addr}
var result Keys
json.Unmarshal([]byte(byteValue), &result)

keys := result.Masternodes
owner := result.Owner
// Validator Smart Contract Code

signers := []common.Address{}
validatorCap := new(big.Int)
validatorCap.SetString("50000000000000000000000", 10)
validatorCaps := []*big.Int{validatorCap}
validatorCaps := []*big.Int{}

for _, key := range keys {
pKey, _ := crypto.HexToECDSA(key)
addr := crypto.PubkeyToAddress(pKey.PublicKey)
addr = crypto.PubkeyToAddress(pKey.PublicKey)
signers = append(signers, addr)
validatorCaps = append(validatorCaps, validatorCap)
}

pKey, _ := crypto.HexToECDSA(owner)
addr := crypto.PubkeyToAddress(pKey.PublicKey)
addr = crypto.PubkeyToAddress(pKey.PublicKey)

contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(pKey)

validatorAddress, _, err := validatorContract.DeployValidator(transactOpts, contractBackend, signers, validatorCaps, addr)
if err != nil {
@@ -43,15 +71,15 @@ func main() {
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
code, _ := contractBackend.CodeAt(ctx, validatorAddress, nil)
fmt.Println("contract code", common.ToHex(code))
fmt.Println(common.ToHex(code))

storage := make(map[common.Hash]common.Hash)
f := func(key, val common.Hash) bool {
decode := []byte{}
trim := bytes.TrimLeft(val.Bytes(), "\x00")
rlp.DecodeBytes(trim, &decode)
storage[key] = common.BytesToHash(decode)
fmt.Println("DecodeBytes", "value", val.String(), "decode", storage[key].String())
fmt.Println(val.String(), storage[key].String())
return true
}
contractBackend.ForEachStorageAt(ctx, validatorAddress, nil, f)

0 comments on commit 93f0d6b

Please sign in to comment.
You can’t perform that action at this time.