Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
zyjblockchain committed May 13, 2024
2 parents 137bdaf + a1bc7b3 commit 8d91281
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 94 deletions.
9 changes: 5 additions & 4 deletions arns/arns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package arns
import (
"errors"
"fmt"
"github.com/tidwall/gjson"
"io/ioutil"
"io"
"net/http"
"strings"
"time"

"github.com/tidwall/gjson"
)

type ArNS struct {
Expand Down Expand Up @@ -73,7 +74,7 @@ func (a *ArNS) QueryNameCa(domain string) (caAddress string, err error) {
}

// Read the response body
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -108,7 +109,7 @@ func (a *ArNS) GetArNSTxID(caAddress string, domain string) (txId string, err er
}

// Read the response body
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions bundleItem.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func SignBundleItem(signatureType int, signer interface{}, item *types.BundleIte
return err
}
default:
// todo come soon supprot ed25519
return errors.New("not supprot this signType")
// todo come soon support ed25519
return errors.New("not support this signType")
}
id := sha256.Sum256(sigData)
item.Id = utils.Base64Encode(id[:])
Expand Down
17 changes: 9 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/inconshreveable/log15"
"github.com/panjf2000/ants/v2"
"github.com/tidwall/gjson"
"gopkg.in/h2non/gentleman.v2"
"io/ioutil"
"io"
"math"
"math/big"
"net/http"
Expand All @@ -21,6 +17,11 @@ import (
"sync"
"time"

"github.com/inconshreveable/log15"
"github.com/panjf2000/ants/v2"
"github.com/tidwall/gjson"
"gopkg.in/h2non/gentleman.v2"

"github.com/everFinance/goar/types"
"github.com/everFinance/goar/utils"
)
Expand Down Expand Up @@ -524,7 +525,7 @@ func (c *Client) httpGet(_path string) (body []byte, statusCode int, err error)
defer resp.Body.Close()

statusCode = resp.StatusCode
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
return
}

Expand All @@ -543,7 +544,7 @@ func (c *Client) httpPost(_path string, payload []byte) (body []byte, statusCode
defer resp.Body.Close()

statusCode = resp.StatusCode
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
return
}

Expand Down Expand Up @@ -1051,7 +1052,7 @@ func (c *Client) SubmitToWarp(tx *types.Transaction) ([]byte, error) {
return nil, err
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

/**
Expand Down
7 changes: 3 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/everFinance/goar/types"
"github.com/everFinance/goar/utils"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"strconv"
"testing"
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestClient_DownloadChunkData(t *testing.T) {
// assert.NoError(t, err)
//
// t.Log(len(data))
// err = ioutil.WriteFile("photo.jpg", data, 0777)
// err = os.WriteFile("photo.jpg", data, 0777)
// assert.NoError(t, err)
}

Expand Down Expand Up @@ -317,7 +316,7 @@ func TestClient_ConcurrentDownloadChunkData(t *testing.T) {
data, err := c.ConcurrentDownloadChunkData(arId, 0)
// data , err := c.DownloadChunkData(arId)
assert.NoError(t, err)
ioutil.WriteFile("nannan.gif", data, 0666)
os.WriteFile("nannan.gif", data, 0666)
chunks, err := utils.GenerateChunks(data)
assert.NoError(t, err)
dataRoot := utils.Base64Encode(chunks.DataRoot)
Expand All @@ -340,7 +339,7 @@ func TestNewTempConn2(t *testing.T) {
assert.NoError(t, err)
// 0x03641046696c654e616d6520576563686174494d4738302e6a70656718436f6e74656e742d5479706514696d6167652f6a70656700

// by, err := ioutil.ReadFile("/Users/sandyzhou/Downloads/zHZIquAcF8eyYb6SbYUtzu1JJ_oeVCMJvqV7Sy-LP4k")
// by, err := os.ReadFile("/Users/sandyzhou/Downloads/zHZIquAcF8eyYb6SbYUtzu1JJ_oeVCMJvqV7Sy-LP4k")
// assert.NoError(t, err)
// item, err := utils.DecodeBundleItem(by)
// assert.NoError(t, err)
Expand Down
9 changes: 4 additions & 5 deletions example/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"math/big"
"os"
"testing"
Expand Down Expand Up @@ -225,7 +224,7 @@ func TestIOBuffer(t *testing.T) {
itemReader, err := os.Open("test.item")
assert.NoError(t, err)
assert.Equal(t, itemReader.Name(), "test.item")
itemBinary, err := ioutil.ReadFile("test.item")
itemBinary, err := os.ReadFile("test.item")
assert.NoError(t, err)
defer itemReader.Close()
item, err := utils.DecodeBundleItemStream(itemReader)
Expand All @@ -250,7 +249,7 @@ func TestIOBuffere(t *testing.T) {
}

func TestCreateBundleItemStream(t *testing.T) {
data0, err := ioutil.ReadFile("../go.mod")
data0, err := os.ReadFile("../go.mod")
assert.NoError(t, err)
data1, err := os.Open("../go.mod")
assert.NoError(t, err)
Expand All @@ -269,7 +268,7 @@ func TestCreateBundleItemStream(t *testing.T) {
}

func TestPointerAndValueCopy(t *testing.T) {
data0, err := ioutil.ReadFile("../go.mod")
data0, err := os.ReadFile("../go.mod")
assert.NoError(t, err)
data, err := os.Open("../go.mod")
assert.NoError(t, err)
Expand All @@ -294,7 +293,7 @@ func TestReader(t *testing.T) {
data, err := os.Open("../go.mod")
defer data.Close()
assert.NoError(t, err)
data2, err := ioutil.ReadFile("../go.mod")
data2, err := os.ReadFile("../go.mod")
itemSigner, err := goar.NewItemSigner(signer01)
assert.NoError(t, err)
item, err := itemSigner.CreateAndSignItemStream(data, "", "", []types.Tag{
Expand Down
11 changes: 5 additions & 6 deletions example/chunks_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -73,7 +72,7 @@ func assemblyDataTx(bigData []byte, wallet *goar.Wallet, tags []types.Tag) (*typ
// test upload post big size data by chunks
func Test_PostBigDataByChunks(t *testing.T) {
filePath := "./testFile/2mbFile.pdf"
bigData, err := ioutil.ReadFile(filePath)
bigData, err := os.ReadFile(filePath)
assert.NoError(t, err)

tags := []types.Tag{{Name: "Content-Type", Value: "application/pdf"}, {Name: "goar", Value: "testdata"}}
Expand All @@ -90,7 +89,7 @@ func Test_PostBigDataByChunks(t *testing.T) {
// test retry upload(断点重传) post big size data by tx id
func Test_RetryUploadDataByTxId(t *testing.T) {
filePath := "./testFile/3mPhoto.jpg"
bigData, err := ioutil.ReadFile(filePath)
bigData, err := os.ReadFile(filePath)
assert.NoError(t, err)

tags := []types.Tag{{Name: "Content-Type", Value: "application/jpg"}, {Name: "goar", Value: "testdata"}}
Expand Down Expand Up @@ -131,7 +130,7 @@ func Test_RetryUploadDataByTxId(t *testing.T) {
// test continue upload(断点续传) big size data by last time uploader
func Test_ContinueUploadDataByLastUploader(t *testing.T) {
filePath := "./testFile/1.8mPhoto.jpg"
bigData, err := ioutil.ReadFile(filePath)
bigData, err := os.ReadFile(filePath)
assert.NoError(t, err)

tags := []types.Tag{{Name: "Content-Type", Value: "application/jpg"}, {Name: "goar", Value: "1.8mbPhoto"}}
Expand All @@ -151,13 +150,13 @@ func Test_ContinueUploadDataByLastUploader(t *testing.T) {
// then store uploader object to file
jsonUploader, err := json.Marshal(uploader)
assert.NoError(t, err)
err = ioutil.WriteFile("./jsonUploaderFile.json", jsonUploader, 0777)
err = os.WriteFile("./jsonUploaderFile.json", jsonUploader, 0777)
assert.NoError(t, err)
t.Log("sleep time ...")
time.Sleep(5 * time.Second) // sleep 5s

// 2. read uploader object from jsonUploader.json file and continue upload by last time uploader
uploaderBuf, err := ioutil.ReadFile("./jsonUploaderFile.json")
uploaderBuf, err := os.ReadFile("./jsonUploaderFile.json")
assert.NoError(t, err)
lastUploader := &goar.TransactionUploader{}
err = json.Unmarshal(uploaderBuf, lastUploader)
Expand Down
8 changes: 4 additions & 4 deletions example/local_data_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package example

import (
"os"
"testing"

"github.com/everFinance/goar"
"github.com/everFinance/goar/types"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)

func Test_SendData(t *testing.T) {
arNode := "https://arweave.net"
w, err := goar.NewWalletFromPath("./wallet/account1.json", arNode) // your wallet private key
assert.NoError(t, err)

data, err := ioutil.ReadFile("/Users/local/Downloads/abc.jpeg") // local file path
data, err := os.ReadFile("/Users/local/Downloads/abc.jpeg") // local file path
if err != nil {
panic(err)
}
Expand Down
57 changes: 35 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,50 +1,63 @@
module github.com/everFinance/goar

go 1.17
go 1.21.1

toolchain go1.22.1

require (
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/ethereum/go-ethereum v1.10.20
github.com/everFinance/arseeding v1.0.3
github.com/ethereum/go-ethereum v1.13.5
github.com/everFinance/arseeding v1.2.5
github.com/everFinance/everpay-go v0.0.1
github.com/everFinance/goether v1.1.9
github.com/everFinance/gojwk v1.0.0
github.com/everFinance/ttcrsa v1.1.3
github.com/hamba/avro v1.5.6
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac
github.com/inconshreveable/log15 v2.16.0+incompatible
github.com/linkedin/goavro/v2 v2.12.0
github.com/panjf2000/ants/v2 v2.6.0
github.com/shopspring/decimal v1.2.0
github.com/stretchr/testify v1.8.0
github.com/tidwall/gjson v1.14.1
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.14.4
gopkg.in/h2non/gentleman.v2 v2.0.5
)

require (
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/everFinance/ethrpc v1.0.4 // indirect
github.com/getsentry/sentry-go v0.11.0 // indirect
github.com/getsentry/sentry-go v0.25.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/linkedin/goavro/v2 v2.12.0 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.4 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/datatypes v1.0.1 // indirect
gorm.io/gorm v1.22.4 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
5 changes: 3 additions & 2 deletions signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"crypto/rsa"
"crypto/sha256"
"fmt"
"os"

"github.com/everFinance/goar/types"
"github.com/everFinance/goar/utils"
"github.com/everFinance/gojwk"
"io/ioutil"
)

type Signer struct {
Expand All @@ -17,7 +18,7 @@ type Signer struct {
}

func NewSignerFromPath(path string) (*Signer, error) {
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 8d91281

Please sign in to comment.