Skip to content

Commit 9c6d874

Browse files
committed
fix(): fix log
1 parent 5375c7f commit 9c6d874

6 files changed

+20
-23
lines changed

client.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"github.com/inconshreveable/log15"
89
"io/ioutil"
910
"math/big"
1011
"net/http"
@@ -13,12 +14,12 @@ import (
1314
"strconv"
1415
"strings"
1516

16-
"github.com/everFinance/sandy_log/log"
17-
1817
"github.com/everFinance/goar/types"
1918
"github.com/everFinance/goar/utils"
2019
)
2120

21+
var log = log15.New("module", "goar")
22+
2223
// arweave HTTP API: https://docs.arweave.org/developers/server/http-api
2324

2425
type Client struct {
@@ -33,7 +34,7 @@ func NewClient(nodeUrl string, proxyUrl ...string) *Client {
3334
pUrl := proxyUrl[0]
3435
proxyUrl, err := url.Parse(pUrl)
3536
if err != nil {
36-
log.Errorf("url parse error: %v", err)
37+
log.Error("url parse", "error", err)
3738
panic(err)
3839
}
3940
tr := &http.Transport{Proxy: http.ProxyURL(proxyUrl)}

client_broadcast.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ func (c *Client) GetTxDataFromPeers(txId string) ([]byte, error) {
1515
pNode := NewClient("http://" + peer)
1616
data, err := pNode.DownloadChunkData(txId)
1717
if err != nil {
18-
fmt.Printf("get tx data error:%v, peer: %s\n", err, peer)
18+
log.Error("get tx data", "err", err, "peer", peer)
1919
continue
2020
}
21-
fmt.Printf("success get tx data; peer: %s\n", peer)
2221
return data, nil
2322
}
2423

@@ -33,7 +32,6 @@ func (c *Client) BroadcastData(txId string, data []byte, numOfNodes int64) error
3332

3433
count := int64(0)
3534
for _, peer := range peers {
36-
fmt.Printf("upload peer: %s, count: %d\n", peer, count)
3735
arNode := NewClient("http://" + peer)
3836
uploader, err := CreateUploader(arNode, txId, data)
3937
if err != nil {

client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestClient_GetBlockByHeight(t *testing.T) {
181181
cli := NewClient(arNode)
182182
block, err := cli.GetBlockByHeight(793791)
183183
assert.NoError(t, err)
184-
assert.Equal(t, "7YeJpe53rFsEE03yKjGcBQAAw6efgVfSeGNLmPRGY4c", block.Nonce)
184+
assert.Equal(t, "ci2uJhYmdldgkHbScDClCwAA0eqn7dCduAEpLfRorSA", block.Nonce)
185185
}
186186

187187
func TestClient_GetTransactionDataByGateway(t *testing.T) {

go.mod

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ go 1.15
44

55
require (
66
github.com/everFinance/gojwk v1.0.0
7-
github.com/everFinance/sandy_log v1.0.3
87
github.com/everFinance/ttcrsa v1.1.3
8+
github.com/go-stack/stack v1.8.1 // indirect
99
github.com/hamba/avro v1.5.6
10+
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac
11+
github.com/mattn/go-colorable v0.1.11 // indirect
1012
github.com/shopspring/decimal v1.2.0
1113
github.com/stretchr/testify v1.7.0
1214
)

threshold.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"time"
1111

12-
"github.com/everFinance/sandy_log/log"
1312
tcrsa "github.com/everFinance/ttcrsa"
1413
)
1514

@@ -28,10 +27,10 @@ func CreateTcKeyPair(bitSize, k, l int) (shares tcrsa.KeyShareList, meta *tcrsa.
2827
now := time.Now()
2928
keyShares, keyMeta, err := tcrsa.NewKey(bitSize, uint16(k), uint16(l), nil)
3029
if err != nil {
31-
log.Errorf("tcrsa newKey error; bitSize: %d, k: %d, l: %d; err: %v", bitSize, k, l, err)
30+
log.Error("tcrsa newKey", "err", err, "bitSize", bitSize, "k", k, "l", l)
3231
return nil, nil, err
3332
}
34-
log.Debugf("Create bit size = %d rsa threshold keyPair spend time: %s", bitSize, time.Since(now).String())
33+
log.Debug("Create rsa threshold keyPair success", "bitSize", bitSize, "spendTime", time.Since(now).String())
3534
return keyShares, keyMeta, nil
3635
}
3736

@@ -81,20 +80,20 @@ func (ts *TcSign) AssembleSigShares(signedShares tcrsa.SigShareList) ([]byte, er
8180
// verify each signer share
8281
for _, sd := range signedShares {
8382
if err := sd.Verify(ts.pssData, ts.keyMeta); err != nil {
84-
log.Errorf("verify signer %d sign failed; err: %v", sd.Id, err)
83+
log.Error("verify signer sign failed", "err", err, "signer", sd.Id)
8584
return nil, err
8685
}
8786
}
8887
signature, err := signedShares.Join(ts.pssData, ts.keyMeta)
8988
if err != nil {
90-
log.Errorf("signedShares.Join(signDataByPss, meta) error: %v", err)
89+
log.Error("signedShares.Join(signDataByPss, meta)", "err", err)
9190
return nil, err
9291
}
9392

9493
// verify
9594
signHashed := sha256.Sum256(ts.signData)
9695
if err := rsa.VerifyPSS(ts.keyMeta.PublicKey, crypto.SHA256, signHashed[:], signature, nil); err != nil {
97-
log.Errorf("verify signature error; %v", err)
96+
log.Error("verify signature", "err", err)
9897
return nil, err
9998
}
10099
return signature, nil

uploader.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/everFinance/goar/types"
1212
"github.com/everFinance/goar/utils"
13-
"github.com/everFinance/sandy_log/log"
1413
"github.com/shopspring/decimal"
1514
)
1615

@@ -40,15 +39,15 @@ func newUploader(tt *types.Transaction, client *Client) (*TransactionUploader, e
4039
return nil, errors.New("Transaction is not signed.")
4140
}
4241
if tt.Chunks == nil {
43-
log.Warnf("Transaction chunks not perpared.")
42+
log.Warn("Transaction chunks not perpared")
4443
}
4544
// Make a copy of Transaction, zeroing the Data so we can serialize.
4645
tu := &TransactionUploader{
4746
Client: client,
4847
}
4948
da, err := utils.Base64Decode(tt.Data)
5049
if err != nil {
51-
log.Errorf("da, err := utils.Base64Decode(tt.Data) error: %v", err)
50+
log.Error("utils.Base64Decode(tt.Data)", "err", err)
5251
return nil, err
5352

5453
}
@@ -92,7 +91,7 @@ func CreateUploader(api *Client, upload interface{}, data []byte) (*TransactionU
9291
// upload 返回为 SerializedUploader 类型
9392
upload, err = (&TransactionUploader{Client: api}).FromTransactionId(id)
9493
if err != nil {
95-
log.Errorf("(&TransactionUploader{Client: api}).FromTransactionId(id) error: %v", err)
94+
log.Error("(&TransactionUploader{Client: api}).FromTransactionId(id)", "err", err)
9695
return nil, err
9796
}
9897
} else {
@@ -158,7 +157,7 @@ func (tt *TransactionUploader) PctComplete() float64 {
158157
func (tt *TransactionUploader) UploadChunk() error {
159158
defer func() {
160159
if tt.TotalChunks() > 0 {
161-
fmt.Printf("%f%% completes, %d/%d \n", tt.PctComplete(), tt.UploadedChunks(), tt.TotalChunks())
160+
log.Debug("chunks", "uploads", fmt.Sprintf("%f%% completes, %d/%d", tt.PctComplete(), tt.UploadedChunks(), tt.TotalChunks()))
162161
}
163162
}()
164163
if tt.IsComplete() {
@@ -218,8 +217,7 @@ func (tt *TransactionUploader) UploadChunk() error {
218217
if err != nil {
219218
return err
220219
}
221-
body, statusCode, err := tt.Client.SubmitChunks(gc)
222-
fmt.Println("post tx chunk body: ", body)
220+
_, statusCode, err := tt.Client.SubmitChunks(gc)
223221
tt.LastRequestTimeEnd = time.Now().UnixNano() / 1000000
224222
tt.LastResponseStatus = statusCode
225223
if statusCode == 200 {
@@ -317,8 +315,7 @@ func (tt *TransactionUploader) uploadTx(withBody bool) error {
317315
// Post the Transaction with Data.
318316
tt.Transaction.Data = utils.Base64Encode(tt.Data)
319317
}
320-
body, statusCode, err := tt.Client.SubmitTransaction(tt.Transaction)
321-
fmt.Printf("uplaodTx; body: %s, status: %d, txId: %s \n", body, statusCode, tt.Transaction.ID)
318+
_, statusCode, err := tt.Client.SubmitTransaction(tt.Transaction)
322319
if err != nil {
323320
tt.LastResponseError = err.Error()
324321
return errors.New(fmt.Sprintf("Unable to upload Transaction: %d, %v", statusCode, err))

0 commit comments

Comments
 (0)