Skip to content

Commit

Permalink
Sby3 (#235)
Browse files Browse the repository at this point in the history
* update readme, add QueryDealMapList

* add InitExtrinsicsNameForMiner and  InitExtrinsicsNameForOSS, update ExtName
  • Loading branch information
AstaFrode authored Aug 7, 2024
1 parent f015821 commit eb735cd
Show file tree
Hide file tree
Showing 16 changed files with 361 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ MY_ADDR="cXgaee2N8E77JJv9gdsGAckv1Qsf3hqWYf7NL4q6ZuQzuAUtB"
RPC_ADDRS="ws://localhost:9944"

# testnet
BOOTSTRAP_NODES="_dnsaddr.boot-miner-testnet.cess.cloud"
BOOTSTRAP_NODES="_dnsaddr.boot-miner-testnet.cess.network"
4 changes: 2 additions & 2 deletions .env.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MY_ADDR="cXgaee2N8E77JJv9gdsGAckv1Qsf3hqWYf7NL4q6ZuQzuAUtB" # root


# testnet
RPC_ADDRS="wss://testnet-rpc.cess.cloud/ws/"
RPC_ADDRS="wss://testnet-rpc.cess.network/ws/"

# testnet
BOOTSTRAP_NODES="_dnsaddr.boot-miner-testnet.cess.cloud"
BOOTSTRAP_NODES="_dnsaddr.boot-miner-testnet.cess.network"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ If you find any system errors or you have better suggestions, please submit an i
## 📢 Announcement
**CESS test network rpc endpoints**
```
wss://testnet-rpc.cess.cloud/ws/
wss://testnet-rpc.cess.network/ws/
```
**CESS test network bootstrap node**
```
_dnsaddr.boot-miner-testnet.cess.cloud
_dnsaddr.boot-miner-testnet.cess.network
```

## 🚰 CESS test network faucet
Expand All @@ -50,7 +50,7 @@ make check
## 📖 Document

- [Reference](https://pkg.go.dev/github.com/CESSProject/cess-go-sdk)
- [Guidebook](https://docs.cess.cloud/core/developer/cess-sdk/sdk-golang)
- [Guidebook](https://doc.cess.network/developer/cess-sdk/sdk-golang)

## License

Expand Down
3 changes: 3 additions & 0 deletions chain/chainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Chainer interface {
// FileBank
QueryBucket(accountID []byte, bucketName string, block int32) (BucketInfo, error)
QueryDealMap(fid string, block int32) (StorageOrder, error)
QueryDealMapList(block int32) ([]StorageOrder, error)
QueryFile(fid string, block int32) (FileMetadata, error)
QueryRestoralOrder(fragmentHash string, block int32) (RestoralOrderInfo, error)
QueryAllRestoralOrder(block int32) ([]RestoralOrderInfo, error)
Expand Down Expand Up @@ -179,6 +180,8 @@ type Chainer interface {

// extrinsics
InitExtrinsicsName() error
InitExtrinsicsNameForMiner() error
InitExtrinsicsNameForOSS() error
ParseBlockData(blocknumber uint64) (BlockData, error)

// event
Expand Down
456 changes: 272 additions & 184 deletions chain/extrinsic_name.go

Large diffs are not rendered by default.

61 changes: 58 additions & 3 deletions chain/file_bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,64 @@ func (c *ChainClient) QueryDealMap(fid string, block int32) (StorageOrder, error
return data, nil
}

// QueryDealMapList query file storage order list
// - block: block number, less than 0 indicates the latest block
//
// Return:
// - []StorageOrder: file storage order list
// - error: error message
func (c *ChainClient) QueryDealMapList(block int32) ([]StorageOrder, error) {
defer func() {
if err := recover(); err != nil {
log.Println(utils.RecoverError(err))
}
}()
var result []StorageOrder

if !c.GetRpcState() {
return nil, ERR_RPC_CONNECTION
}

key := CreatePrefixedKey(FileBank, DealMap)
keys, err := c.api.RPC.State.GetKeysLatest(key)
if err != nil {
err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] GetKeysLatest: %v", c.GetCurrentRpcAddr(), FileBank, DealMap, err)
c.SetRpcState(false)
return nil, err
}

var set []types.StorageChangeSet
if block < 0 {
set, err = c.api.RPC.State.QueryStorageAtLatest(keys)
if err != nil {
err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] QueryStorageAtLatest: %v", c.GetCurrentRpcAddr(), FileBank, DealMap, err)
c.SetRpcState(false)
return nil, err
}
} else {
blockhash, err := c.api.RPC.Chain.GetBlockHash(uint64(block))
if err != nil {
return nil, err
}
set, err = c.api.RPC.State.QueryStorageAt(keys, blockhash)
if err != nil {
err = fmt.Errorf("rpc err: [%s] [st] [%s.%s] QueryStorageAtLatest: %v", c.GetCurrentRpcAddr(), FileBank, DealMap, err)
c.SetRpcState(false)
return nil, err
}
}
for _, elem := range set {
for _, change := range elem.Changes {
var data StorageOrder
if err := codec.Decode(change.StorageData, &data); err != nil {
continue
}
result = append(result, data)
}
}
return result, nil
}

// QueryFile query file metadata
// - fid: file identification
// - block: block number, less than 0 indicates the latest block
Expand Down Expand Up @@ -747,9 +805,6 @@ func (c *ChainClient) UploadDeclaration(fid string, segment []SegmentList, user
// Note:
// - cannot create a bucket that already exists
// - if you are not the owner, the owner account must be authorised to you
//
// For details on bucket naming rules, see:
// - https://docs.cess.cloud/deoss/get-started/deoss-gateway/step-1-create-a-bucket#naming-conventions-for-a-bucket
func (c *ChainClient) CreateBucket(owner []byte, bucketName string) (string, error) {
c.lock.Lock()
defer func() {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
CharacterName_Default = "cess-sdk-go"

// offcial gateway address
PublicGatewayAddr = "http://deoss-pub-gateway.cess.cloud/"
PublicGatewayAddr = "https://deoss-pub-gateway.cess.network/"
// offcial gateway account
PublicGatewayAccount = "cXhwBytXqrZLr1qM5NHJhCzEMckSTzNKw17ci2aHft6ETSQm9"
)
4 changes: 2 additions & 2 deletions core/process/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var globalTransport = &http.Transport{
//
// Explanation:
// - Account refers to the account where you configured mnemonic when creating an SDK.
// - CESS public gateway address: [http://deoss-pub-gateway.cess.cloud/]
// - CESS public gateway address: [https://deoss-pub-gateway.cess.network/]
// - CESS public gateway account: [cXhwBytXqrZLr1qM5NHJhCzEMckSTzNKw17ci2aHft6ETSQm9]
func StoreFile(url, file, bucket, territory, mnemonic string) (string, error) {
fstat, err := os.Stat(file)
Expand Down Expand Up @@ -165,7 +165,7 @@ func StoreFile(url, file, bucket, territory, mnemonic string) (string, error) {
//
// Explanation:
// - Account refers to the account where you configured mnemonic when creating an SDK.
// - CESS public gateway address: [http://deoss-pub-gateway.cess.cloud/]
// - CESS public gateway address: [https://deoss-pub-gateway.cess.network/]
// - CESS public gateway account: [cXhwBytXqrZLr1qM5NHJhCzEMckSTzNKw17ci2aHft6ETSQm9]
func StoreObject(url string, bucket, territory, mnemonic string, reader io.Reader) (string, error) {
if !utils.CheckBucketName(bucket) {
Expand Down
2 changes: 1 addition & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// DefaultRpcAddrs configures the default rpc address
var DefaultRpcAddrs = func(cfg *Config) error {
rpcAddrs := []string{
"wss://testnet-rpc.cess.cloud/ws/",
"wss://testnet-rpc.cess.network/ws/",
}
return cfg.Apply(ConnectRpcAddrs(rpcAddrs))
}
Expand Down
2 changes: 1 addition & 1 deletion example/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var MY_MNEMONIC = "head achieve piano online exhaust bulk trust vote inflict roo

var RPC_ADDRS = []string{
//testnet
"wss://testnet-rpc.cess.cloud/ws/",
"wss://testnet-rpc.cess.network/ws/",
}

func main() {
Expand Down
4 changes: 2 additions & 2 deletions example/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ var MY_MNEMONIC = "bottom drive obey lake curtain smoke basket hold race lonely

var RPC_ADDRS = []string{
//testnet
"wss://testnet-rpc.cess.cloud/ws/",
"wss://testnet-rpc.cess.network/ws/",
}

const PublicGateway = "http://deoss-pub-gateway.cess.cloud/"
const PublicGateway = "https://deoss-pub-gateway.cess.network/"
const PublicGatewayAccount = "cXhwBytXqrZLr1qM5NHJhCzEMckSTzNKw17ci2aHft6ETSQm9"
const UploadFile = "file.go"
const BucketName = "myBucket"
Expand Down
14 changes: 10 additions & 4 deletions example/new/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ import (
var MY_MNEMONIC = "bottom drive obey lake curtain smoke basket hold race lonely fit walk"

var RPC_ADDRS = []string{
//devnet
"wss://testnet-rpc.cess.cloud/ws/",

//testnet
//"wss://testnet-rpc.cess.cloud/ws/",
"wss://testnet-rpc.cess.network/ws/",
}

func main() {
Expand All @@ -43,13 +40,22 @@ func main() {
}
defer sdk.Close()

err = sdk.InitExtrinsicsNameForMiner()
if err != nil {
panic(err)
}
err = sdk.InitExtrinsicsNameForOSS()
if err != nil {
panic(err)
}
err = sdk.InitExtrinsicsName()
if err != nil {
panic(err)
}

fmt.Println(sdk.SystemVersion())
fmt.Println(sdk.GetCurrentRpcAddr())
fmt.Println(sdk.SystemProperties())
return

puk, err := utils.ParsingPublickey("cXfg2SYcq85nyZ1U4ccx6QnAgSeLQB8aXZ2jstbw9CPGSmhXY")
Expand Down
11 changes: 2 additions & 9 deletions example/parse_block/parse_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@ import (
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
)

// Substrate well-known mnemonic:
//
// https://github.com/substrate-developer-hub/substrate-developer-hub.github.io/issues/613
var MY_MNEMONIC = "bottom drive obey lake curtain smoke basket hold race lonely fit walk"

var RPC_ADDRS = []string{
//devnet
"wss://devnet-rpc.cess.cloud/ws/",
//testnet
// "wss://testnet-rpc.cess.cloud/ws/",
"wss://testnet-rpc.cess.network/ws/",
}

type MyEvent struct {
Expand All @@ -42,7 +35,7 @@ func main() {
panic(err)
}

blockData, err := sdk.ParseBlockData(43742)
blockData, err := sdk.ParseBlockData(24112)
if err != nil {
fmt.Println("ERR: ", err)
return
Expand Down
10 changes: 1 addition & 9 deletions example/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ package main

import (
"context"
"fmt"

sdkgo "github.com/CESSProject/cess-go-sdk"
)

var RPC_ADDRS = []string{
//testnet
"wss://testnet-rpc.cess.cloud/ws/",
"wss://testnet-rpc.cess.network/ws/",
}

func main() {
Expand All @@ -28,11 +27,4 @@ func main() {
panic(err)
}
defer sdk.Close()

blockhash, err := sdk.ChainGetBlockHash(0)
if err != nil {
panic(err)
}

fmt.Println(sdk.ChainGetBlock(blockhash))
}
2 changes: 1 addition & 1 deletion sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// reasonable defaults. The defaults are:
//
// - If no rpc address is provided, the sdk client uses the default address
// "wss://testnet-rpc0.cess.cloud/ws/"" or "wss://testnet-rpc1.cess.cloud/ws/";
// "wss://testnet-rpc.cess.network/ws/"
//
// - If no transaction timeout is provided, the sdk client uses the default
// timeout: time.Duration(time.Second * 6)
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
package sdkgo

// SDK Version
const Version = "0.6.0"
const Version = "0.6.1"

0 comments on commit eb735cd

Please sign in to comment.