Commit 8e9d6b47 authored by 李伟@五瓣科技's avatar 李伟@五瓣科技

web data as hex

parent a330bbc2
......@@ -12,7 +12,6 @@ import (
"sync/atomic"
"time"
"encoding/base64"
"sync"
"github.com/ethereum/go-ethereum/common"
......@@ -55,6 +54,11 @@ type ConsTxWithBatchHash struct {
BatchTxsHash []byte `json:"batch_txs_hash"`
}
type ConsTxWithBatchHashAsHex struct {
ConsTxHash string `json:"cons_tx_hash"`
BatchTxsHash []string `json:"batch_txs_hash"`
}
type BatchSend struct {
SendToRedisBeginTime int64 `json:"send_to_redis_begin_time"`
SendTxsEndTime int64 `json:"send_txs_end_time"`
......@@ -132,20 +136,36 @@ func (web *WebServicer) GetTreeHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
consTxWithBatchHashAsHex := []ConsTxWithBatchHashAsHex{}
if record, ok := GetSendRecord(id); ok {
consTxWithBatchHash := []ConsTxWithBatchHash{}
for _, v := range record.SendRecord {
consTxWithBatchHash = append(consTxWithBatchHash, v.ConsTxWithBatchHash...)
}
for _, v1 := range v.ConsTxWithBatchHash {
batchTxsAsHex := []string{}
// for _, hashAsBytes := range v1.BatchTxsHash {
// batchTxsAsHex = append(batchTxsAsHex, fmt.Sprintf("%x", hashAsBytes))
// }
for i := 0; ; i++ {
for k, v := range consTxWithBatchHash {
fmt.Printf("idx: %d v: %d \n", k, len(v.BatchTxsHash))
if len(v1.BatchTxsHash) < 32 {
break
}
batchTxsAsHex = append(batchTxsAsHex, fmt.Sprintf("%x", v1.BatchTxsHash[:32]))
v1.BatchTxsHash = v1.BatchTxsHash[32:]
}
consTxWithBatchHashAsHex = append(consTxWithBatchHashAsHex,
ConsTxWithBatchHashAsHex{
ConsTxHash: fmt.Sprintf("%x", v1.ConsTxHash),
BatchTxsHash: batchTxsAsHex,
})
}
}
recordAsJon, err := json.Marshal(consTxWithBatchHash)
recordAsJon, err := json.Marshal(consTxWithBatchHashAsHex)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
......@@ -195,27 +215,29 @@ func (web *WebServicer) GetTxsList(w http.ResponseWriter, r *http.Request) {
fmt.Printf("startAsStr: %s offsetStr: %s startAs: %d offset: %d \n", startAsStr, numStr, startAsInt, numInt)
hashAsBytes, err := base64.StdEncoding.DecodeString(hashStr)
// hashAsBytes, err := base64.StdEncoding.DecodeString(hashStr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
total, err := redisCli.LLen(context.Background(), fmt.Sprintf("%x", hashAsBytes)).Uint64()
//total, err := redisCli.LLen(context.Background(), fmt.Sprintf("%x", hashAsBytes)).Uint64()
total, err := redisCli.LLen(context.Background(), hashStr).Uint64()
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
res, err := redisCli.LRange(context.Background(), fmt.Sprintf("%x", hashAsBytes), int64(startAsInt*numInt), int64((startAsInt+1)*numInt)-1).Result()
//res, err := redisCli.LRange(context.Background(), fmt.Sprintf("%x", hashAsBytes), int64(startAsInt*numInt), int64((startAsInt+1)*numInt)-1).Result()
res, err := redisCli.LRange(context.Background(), hashStr, int64(startAsInt*numInt), int64((startAsInt+1)*numInt)-1).Result()
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Printf("hashStr: %s len(hashStr): %d len(hashAsBytes): %d int64(startAsInt*numInt): %d int64((startAsInt+1)*numInt): %d res: %v \n", hashStr, len(hashStr), len(hashAsBytes), int64(startAsInt*numInt), int64((startAsInt+1)*numInt-1), res)
fmt.Printf("hashStr: %s len(hashStr): %d int64(startAsInt*numInt): %d int64((startAsInt+1)*numInt): %d res: %v \n", hashStr, len(hashStr), int64(startAsInt*numInt), int64((startAsInt+1)*numInt-1), res)
resp := resp{
HashList: res,
......@@ -412,6 +434,8 @@ type WebResp struct {
func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount int, amount int64, id uuid.UUID) error {
consTxNum := 0
addrsL := len(toAddrs)
for {
var hashesBytes []byte = make([]byte, 0, 32*batchTxHashSize)
......@@ -425,7 +449,7 @@ 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, toAddress, big.NewInt(256), nil)
tx, err := buildOriginalTx(originalTxParam.Nonce, common.HexToAddress(toAddrs[i%addrsL]), big.NewInt(256), nil)
if err != nil {
return err
}
......
......@@ -91,13 +91,18 @@ func Start(redisAddr, passwd string) {
// panic(err)
// }
for k, v := range hashs {
hashstr := []string{}
fmt.Printf("idx: %d key: %s v: %s \n", k, fmt.Sprintf("%x", batchTxs.Hash), v.Hex())
for _, v := range hashs {
//fmt.Printf("idx: %d key: %s v: %s \n", k, fmt.Sprintf("%x", batchTxs.Hash), v.Hex())
hashstr = append(hashstr, v.Hex())
}
fmt.Printf("batchTxHash %s list: %v \n", fmt.Sprintf("%x", batchTxs.Hash), hashstr)
if err := client.LPush(context.Background(), fmt.Sprintf("%x", batchTxs.Hash), hashstr); err != nil {
if err := client.LPush(context.Background(), fmt.Sprintf("%x", batchTxs.Hash), v.Hex()); err != nil {
//panic(err)
}
}
count += 1
......
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