Skip to content

Commit

Permalink
cli: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyilanzhou committed Apr 3, 2020
1 parent 1d3623f commit 4681dff
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 18 deletions.
12 changes: 12 additions & 0 deletions cmd/impawn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ This command will:
* Load private key in key/bftkey file, connect http://39.100.97.129:8545 node.
* Sub command only update validator fee(0-10000), which will influence delegator benefit.

### UpdatePK

```
$ impawn --key key/bftkey --rpcaddr 39.100.97.129 --rpcport 8545 --bftkey f0f9fa54c701cdbc3e87adbe3936d2cafef66c9e018d0302587e932dab58fd85 updatepk
```

This command will:

* Load private key in key/bftkey file, connect http://39.100.97.129:8545 node.
* Sub command only update validator pk, you can use --bftkey + private key or --pubkey + public key .

### Send

```
Expand Down
45 changes: 28 additions & 17 deletions send_transaction/stake/stake_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"fmt"
ethereum "github.com/truechain/truechain-engineering-code"
"github.com/truechain/truechain-engineering-code/cmd/utils"
Expand Down Expand Up @@ -127,9 +128,10 @@ func queryLogImpawn(ctx *cli.Context) error {
}

func filterLogs(client *etrueclient.Client) {
method := "Deposit"
contractAddress := types.StakingAddress
//address := common.HexToAddress("0x25e7ba30a8ca432996553987da8d9f855016059b")
event := abiStaking.Events["SetFee"]
event := abiStaking.Events[method]

var nodeRule []interface{}
//nodeRule = append(nodeRule, address.Bytes())
Expand All @@ -148,7 +150,7 @@ func filterLogs(client *etrueclient.Client) {
log.Fatal(err)
}

for i := uint64(4706256); i < header.Number.Uint64(); {
for i := uint64(4706111); i < header.Number.Uint64(); {
query := ethereum.FilterQuery{
FromBlock: new(big.Int).SetUint64(i),
ToBlock: new(big.Int).SetUint64(i + 100),
Expand All @@ -164,26 +166,35 @@ func filterLogs(client *etrueclient.Client) {
}

for _, vLog := range logs {
fmt.Println("BlockHash ", vLog.BlockHash.Hex()) // 0x3404b8c050aa0aacd0223e91b5c32fee6400f357764771d0684fa7b3f448f1a8
fmt.Println("BlockNumber ", vLog.BlockNumber) // 2394201
fmt.Println("TxHash ", vLog.TxHash.Hex()) // 0x280201eda63c9ff6f305fcee51d5eb86167fab40ca3108ec784e8652a0e2b1a6

FeeS := struct {
Fee *big.Int
}{}
err := abiStaking.Unpack(&FeeS, "SetFee", vLog.Data)
if err != nil {
log.Fatal(err)
fmt.Println("BlockNumber ", vLog.BlockNumber, " TxHash ", vLog.TxHash.Hex(), " BlockHash ", vLog.BlockHash.Hex()) // 2394201
if method == "SetFee" {
FeeS := struct {
Fee *big.Int
}{}
err := abiStaking.Unpack(&FeeS, "SetFee", vLog.Data)
if err != nil {
log.Fatal(err)
}
fmt.Println("fee ", FeeS.Fee) // foo
} else if method == "Deposit" {
deposit := struct {
Pubkey []byte
Value *big.Int
Fee *big.Int
}{}
err := abiStaking.Unpack(&deposit, "Deposit", vLog.Data)
if err != nil {
log.Fatal(err)
}
fmt.Println("value", types.ToTrue(deposit.Value), "fee ", deposit.Fee, "pk", hex.EncodeToString(deposit.Pubkey)) // foo
}
fmt.Println("fee ", FeeS.Fee) // foo

for i := range vLog.Topics {
fmt.Println(vLog.Topics[i]) // 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4
fmt.Println("i ", i, " topic ", vLog.Topics[i].String()) // 0xe79e73da417710ae99aa2088575580a60415d359acfad9cdd3382d59c80281d4
}

}
i = i + 100
if i%10000 == 0 {
if i%1000 == 0 {
fmt.Println("index ", i)
}
}
Expand Down Expand Up @@ -267,7 +278,7 @@ var queryRewardCommand = cli.Command{
Name: "queryreward",
Usage: "Query committee reward info, contain deposit and delegate reward",
Action: utils.MigrateFlags(queryRewardImpawn),
Flags: append(ImpawnFlags, AddressFlag),
Flags: append(ImpawnFlags, SnailNumberFlag),
}

func queryRewardImpawn(ctx *cli.Context) error {
Expand Down
29 changes: 28 additions & 1 deletion send_transaction/test/stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,48 @@ func TestGetAddress(t *testing.T) {
saddr := crypto.PubkeyToAddress(skey.PublicKey)
skey2, _ := crypto.HexToECDSA("48552cb89a19028d116c7853c460f0c76d50cddaf2d7c217ac611b696e4680c6")
saddr2 := crypto.PubkeyToAddress(skey2.PublicKey)
//103
skey3, _ := crypto.HexToECDSA("6e7595dcb8eda2213c1a0940c4920ce7db89d8f805fc4e85567fd1355c83cff2")
saddr3 := crypto.PubkeyToAddress(skey3.PublicKey)
//104
skey4, _ := crypto.HexToECDSA("62eab9d8657c25330f587c2fbb292a559ed27ddb391b9efe6014f920e67d2f1a")
saddr4 := crypto.PubkeyToAddress(skey4.PublicKey)

fmt.Println("saddr", saddr.String(), "saddr2", saddr2.String(), "saddr3", saddr3.String(), "saddr26 ", saddr4.String())
fmt.Println("saddr", saddr.String(), "saddr2", saddr2.String(), "saddr3", saddr3.String(), "saddr4 ", saddr4.String())

//105
skey5, _ := crypto.HexToECDSA("dbb0d9954bef0db91d7d15c44855cb0d0e662d01ac2a15d31d38724236802fbd")
saddr5 := crypto.PubkeyToAddress(skey5.PublicKey)
//106
skey6, _ := crypto.HexToECDSA("2801712bcc44a58f4b2d0e74df50b9875747d60f0b8a133ea591276ca004ad3e")
saddr6 := crypto.PubkeyToAddress(skey6.PublicKey)
// 011
skey7, _ := crypto.HexToECDSA("5e6ea3e3ba8a3d8940088247eda01a0909320f729ae3afcdc5747b2ced1ac460")
saddr7 := crypto.PubkeyToAddress(skey7.PublicKey)

fmt.Println("saddr5", saddr5.String(), "saddr6", saddr6.String(), "saddr7", saddr7.String())

// 107
skey8, _ := crypto.HexToECDSA("597bce6754f85ddf16f3ef04d5561da43b9cf9b6418b25ca3987a7af42d2e47c")
saddr8 := crypto.PubkeyToAddress(skey8.PublicKey)
//031
skey9, _ := crypto.HexToECDSA("3e1a89b7f3ed62a8a7b7a7511ccfb303d1fa76f9c12d954071984b5209d068a3")
saddr9 := crypto.PubkeyToAddress(skey9.PublicKey)
//111
skey10, _ := crypto.HexToECDSA("f0f9fa54c701cdbc3e87adbe3936d2cafef66c9e018d0302587e932dab58fd85")
saddr10 := crypto.PubkeyToAddress(skey10.PublicKey)

fmt.Println("saddr8", saddr8.String(), "saddr9", saddr9.String(), "saddr10", saddr10.String())

pub101 := hex.EncodeToString(crypto.FromECDSAPub(&skey2.PublicKey))
pub102 := hex.EncodeToString(crypto.FromECDSAPub(&skey2.PublicKey))
pub103 := hex.EncodeToString(crypto.FromECDSAPub(&skey3.PublicKey))
pub104 := hex.EncodeToString(crypto.FromECDSAPub(&skey4.PublicKey))
pub105 := hex.EncodeToString(crypto.FromECDSAPub(&skey5.PublicKey))
pub106 := hex.EncodeToString(crypto.FromECDSAPub(&skey6.PublicKey))
pub011 := hex.EncodeToString(crypto.FromECDSAPub(&skey7.PublicKey))
fmt.Println("pub101", pub101, "pub102", pub102, "pub103", pub103, "pub104 ", pub104)
fmt.Println("pub105", pub105, "pub106", pub106, "pub011", pub011)
}

func TestDepositCancelInSameEpoch(t *testing.T) {
Expand Down

0 comments on commit 4681dff

Please sign in to comment.