Commit 2a3647b6 authored by 李伟@五瓣科技's avatar 李伟@五瓣科技

first tx amount with diff from

parent ba73e98d
......@@ -15,6 +15,7 @@ import (
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/google/uuid"
"github.com/gorilla/mux"
hdwallet "github.com/miguelmota/go-ethereum-hdwallet"
......@@ -27,6 +28,24 @@ var mnemonic = "matter someone fee garlic final police during vapor stool cargo
var processMap sync.Map
var Running int32 = 0
var systemFromAddr string
func init() {
wallet, err := hdwallet.NewFromMnemonic(mnemonic)
if err != nil {
log.Fatal(err)
}
path := hdwallet.MustParseDerivationPath(fmt.Sprintf("m/44'/60'/0'/0/%d", 0))
account, err := wallet.Derive(path, false)
if err != nil {
panic(err)
}
systemFromAddr = account.Address.Hex()
}
func GetSendRecord(id uuid.UUID) (SendRecord, bool) {
if vAsInterface, ok := processMap.Load(id); ok {
......@@ -36,11 +55,39 @@ func GetSendRecord(id uuid.UUID) (SendRecord, bool) {
}
}
recordAsJson, err := redisCli.Get(context.Background(), id.String()).Result()
if err != nil {
panic(err)
}
fmt.Printf("recordAsJson: %s \n", recordAsJson)
// sendRec := SendRecord{}
// if err := json.Unmarshal([]byte(recordAsJson), sendRec); err != nil {
// panic(err)
// }
return SendRecord{}, false
}
func SetSendRecord(id uuid.UUID, value SendRecord) {
processMap.Store(id, value)
sent := 0
for _, v := range value.SendRecord {
sent += v.TxNum
}
if sent == int(value.TotalConsTx) {
recoradAsJson, err := json.Marshal(value)
if err != nil {
panic(err)
}
redisCli.Set(context.Background(), id.String(), recoradAsJson, time.Hour*24)
}
}
type SendRecord struct {
......@@ -175,6 +222,8 @@ func (web *WebServicer) GetTreeHandler(w http.ResponseWriter, r *http.Request) {
}
// record := redisCli.Get(context.Background(), id.String()).Scan()
if err != nil {
http.Error(w, fmt.Sprintf("can not find the uuid: %s ", id.String()), http.StatusInternalServerError)
return
......@@ -432,6 +481,8 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
addrsL := len(toAddrs)
first := true
for {
var hashesBytes []byte = make([]byte, 0, 32*batchTxHashSize)
......@@ -445,7 +496,17 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
txshash := make([]string, 0, batchTxSize)
for i := 0; i < batchTxSize; i++ {
tx, err := buildOriginalTx(originalTxParam.Nonce, common.HexToAddress(toAddrs[i%addrsL]), amount, big.NewInt(256), nil)
var tx *types.Transaction
var err error
if fromAddr != systemFromAddr && first {
tx, err = buildOriginalTx(originalTxParam.Nonce, common.HexToAddress(fromAddr), amount*int64(txCount), big.NewInt(256), nil)
first = false
} else {
tx, err = buildOriginalTx(originalTxParam.Nonce, common.HexToAddress(toAddrs[i%addrsL]), amount, big.NewInt(256), nil)
}
if err != nil {
return err
}
......@@ -465,6 +526,16 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
txsBytes = append(txsBytes, txAsBytes...)
if fromAddr != systemFromAddr && first {
txs = append(txs, TxWithFrom{
[]byte(systemFromAddr),
tx})
} else {
txs = append(txs, TxWithFrom{
originalTxParam.FromAddr[:],
tx})
}
txs = append(txs, TxWithFrom{
originalTxParam.FromAddr[:],
tx})
......
package multisend
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/google/uuid"
)
func TestRateLimit(t *testing.T) {
......@@ -23,3 +28,34 @@ func TestRateLimit(t *testing.T) {
// }
}
type Person struct {
Name string `json:"name"`
Age int64 `json:"age"`
}
func TestSetGetJson(t *testing.T) {
client := initClient(10, "13.40.18.11:6379", "redis20220217")
id := uuid.New()
p1 := Person{
Name: "alice",
Age: 10,
}
p1AsJson, err := json.Marshal(p1)
if err != nil {
panic(err)
}
client.Set(context.Background(), id.String(), p1AsJson, time.Hour*24)
recordAsJson, err := client.Get(context.Background(), "111").Result()
if err != nil {
panic(err)
}
t.Logf("recordAsJson: %s \n", recordAsJson)
}
......@@ -322,6 +322,7 @@ func (t *Transactor) sendTransactions() error {
record.SendRecord = append(record.SendRecord, b)
SetSendRecord(id, record)
}
return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment