Skip to content

Commit

Permalink
Base cmm3 (#97)
Browse files Browse the repository at this point in the history
* add example.go

* update p2p to v0.0.36

* update example
  • Loading branch information
AstaFrode authored Jul 4, 2023
1 parent 66e5ed6 commit 0cee833
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 3 deletions.
95 changes: 95 additions & 0 deletions example/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"fmt"
"time"

cess "github.com/CESSProject/cess-go-sdk"
"github.com/CESSProject/cess-go-sdk/config"
"github.com/CESSProject/cess-go-sdk/core/utils"
"github.com/centrifuge/go-substrate-rpc-client/v4/signature"
)

// 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{
"wss://testnet-rpc0.cess.cloud/ws/",
"wss://testnet-rpc1.cess.cloud/ws/",
}

var Workspace = "/cess"
var Port = 4001
var Bootstrap = []string{
"_dnsaddr.sjc-1.bootstrap-kldr.cess.cloud",
}

const File = "/home/test_download"
const BucketName = "myBucket"
const FileHash = "c158d7008e94d3af61033b6861aa4f35a4c2b829c7e97224fcbb54618de55945"

func main() {
RetrieveFile()
}

func RetrieveFile() {
sdk, err := cess.New(
config.CharacterName_Client,
cess.ConnectRpcAddrs(RPC_ADDRS),
cess.Mnemonic(MY_MNEMONIC),
cess.TransactionTimeout(time.Second*10),
cess.Workspace(Workspace),
cess.P2pPort(Port),
cess.Bootnodes(Bootstrap),
)
if err != nil {
panic(err)
}

fmt.Println(sdk.RetrieveFile(FileHash, File))
}

func StoreFile() {
sdk, err := cess.New(
config.CharacterName_Client,
cess.ConnectRpcAddrs(RPC_ADDRS),
cess.Mnemonic(MY_MNEMONIC),
cess.TransactionTimeout(time.Second*10),
cess.Workspace(Workspace),
cess.P2pPort(Port),
cess.Bootnodes(Bootstrap),
)
if err != nil {
panic(err)
}

keyringPair, err := signature.KeyringPairFromSecret(MY_MNEMONIC, 0)

if !utils.CheckBucketName(BucketName) {
panic("invalid bucket name")
}

fmt.Println(sdk.StoreFile(keyringPair.PublicKey, File, BucketName))
}

func CreateBucket() {
sdk, err := cess.New(
config.CharacterName_Client,
cess.ConnectRpcAddrs(RPC_ADDRS),
cess.Mnemonic(MY_MNEMONIC),
cess.TransactionTimeout(time.Second*10),
)
if err != nil {
panic(err)
}

keyringPair, err := signature.KeyringPairFromSecret(MY_MNEMONIC, 0)

if !utils.CheckBucketName(BucketName) {
panic("invalid bucket name")
}

fmt.Println(sdk.CreateBucket(keyringPair.PublicKey, BucketName))
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/CESSProject/cess-go-sdk
go 1.19

require (
github.com/CESSProject/p2p-go v0.0.35
github.com/CESSProject/p2p-go v0.0.36
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cbergoon/merkletree v0.2.0
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.13
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CESSProject/p2p-go v0.0.35 h1:hrCfmO4DGaMrbCzA9urqITb+zrym41SEokUUXSx+jq4=
github.com/CESSProject/p2p-go v0.0.35/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw=
github.com/CESSProject/p2p-go v0.0.36 h1:FyXwuE6nrfgsb32BdTgQdZeSUqLjI/KHchOTIFiLn8c=
github.com/CESSProject/p2p-go v0.0.36/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw=
github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM=
github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
Expand Down

0 comments on commit 0cee833

Please sign in to comment.