Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
startNonce get from rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhnguyennguyen committed Nov 27, 2019
1 parent 4cd6e73 commit eec8c7c
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ send orders to tomox rpc
cp build/tomox-bot-linux-amd64 ./bot
# run bot
./bot 6
# send tomox orders starting with orderNonce = 6
./bot
```
Argument:
- StartNonce
Expand Down
31 changes: 16 additions & 15 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func buildOrder(nonce *big.Int) *tomox_state.OrderItem {
return order
}

func sendOrder(nonce *big.Int) {
func sendOrder(rpcClient *rpc.Client, nonce *big.Int) {
order := buildOrder(nonce)
order.Hash = ComputeHash(order)

Expand All @@ -100,15 +100,6 @@ func sendOrder(nonce *big.Int) {
}
order.Signature = sig


//create topic
rpcClient, err := rpc.DialHTTP(os.Getenv("RPC_ENDPOINT"))
defer rpcClient.Close()
if err != nil {
fmt.Println("rpc.DialHTTP failed", "err", err)
os.Exit(1)
}

orderMsg := OrderMsg{
AccountNonce: order.Nonce.Uint64(),
Quantity: order.Quantity,
Expand All @@ -128,7 +119,7 @@ func sendOrder(nonce *big.Int) {
var result interface{}


err = rpcClient.Call(&result, "tomox_sendOrder", orderMsg)
err := rpcClient.Call(&result, "tomox_sendOrder", orderMsg)
if err != nil {
fmt.Println("rpcClient.Call tomox_sendOrder failed", "err", err)
os.Exit(1)
Expand All @@ -140,13 +131,23 @@ func main() {
if err != nil {
panic("Error loading .env file")
}
startNonce := int(0)
if len(os.Args) > 1 {
startNonce, _ = strconv.Atoi(os.Args[1])
rpcClient, err := rpc.DialHTTP(os.Getenv("RPC_ENDPOINT"))
defer rpcClient.Close()
if err != nil {
fmt.Println("rpc.DialHTTP failed", "err", err)
os.Exit(1)
}
var result interface{}
err = rpcClient.Call(&result, "tomox_getOrderCount", os.Getenv("USER_ADDRESS"))
if err != nil {
fmt.Println("rpcClient.Call tomox_getOrderCount failed", "err", err)
os.Exit(1)
}
startNonce, _ := strconv.ParseInt(strings.TrimLeft(result.(string), "0x"), 16, 64)
fmt.Println("Your current orderNonce: ", startNonce)
breakTime, _ := strconv.Atoi(os.Getenv("BREAK_TIME"))
for {
sendOrder(new(big.Int).SetUint64(uint64(startNonce)))
sendOrder(rpcClient, new(big.Int).SetUint64(uint64(startNonce)))
time.Sleep(time.Duration(int64(breakTime)) * time.Millisecond)
startNonce++
}
Expand Down
Binary file modified build/tomox-bot-darwin-386
Binary file not shown.
Binary file modified build/tomox-bot-darwin-amd64
Binary file not shown.
Binary file modified build/tomox-bot-linux-386
Binary file not shown.
Binary file modified build/tomox-bot-linux-amd64
Binary file not shown.
Binary file modified build/tomox-bot-windows-386
Binary file not shown.
Binary file modified build/tomox-bot-windows-amd64
Binary file not shown.

0 comments on commit eec8c7c

Please sign in to comment.