Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winsdk demo #1296

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions winsdk/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### Introduction

Demo to try out winsdk

usage:
```
# first compile winsdk from the root of the gosdk project
make build-windows

# copy the generated DLLs into the demo folder
cp winsdk/zcn.windows.* winsdk/demo/

# run demo
cd winsdk/demo
go run main.go
```
1 change: 1 addition & 0 deletions winsdk/demo/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a sample file to test upload
14 changes: 14 additions & 0 deletions winsdk/demo/client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"client_id": "5ad6e4d206d853833e96ff5c833369e567d2ef41ae1d5093141e1f90f1e8dcb0",
"client_key": "06b7735844c07c6918b83bacbd2caa57b41888b5222621fa18ab916160f81a0d3cd574feb6930e7607fd454f4aa2f4dbbfa95532bb9d76cde492b50946eab5a1",
"keys": [
{
"public_key": "06b7735844c07c6918b83bacbd2caa57b41888b5222621fa18ab916160f81a0d3cd574feb6930e7607fd454f4aa2f4dbbfa95532bb9d76cde492b50946eab5a1",
"private_key": "0bb11cd6dcfa34acabfee25babe815bfcd6a4870bd7ebd3b205429b24dde2522"
}
],
"mnemonics": "border laptop library theory pave brain decline jeans winner frame throw gadget amused mule farm labor torch slight pride lottery cash youth ocean route",
"version": "1.0",
"date_created": "2023-05-30T01:31:32+02:00",
"nonce": 0
}
15 changes: 15 additions & 0 deletions winsdk/demo/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"block_worker": "https://dev.zus.network/dns",
"signature_scheme": "bls0chain",
"min_submit": 50,
"min_confirmation": 50,
"confirmation_chain_length": 3,
"max_txn_query": 5,
"query_sleep_time": 5,
"preferred_blobbers": [],
"chain_id": "0afc093ffb509f059c55478bc1a60351cef7b4e9c008a53a6cc8241ca8617dfe",
"ethereum_node": "https://ropsten.infura.io/v3/xxxxxxxxxxxxxxx",
"zbox_host": "https://0box.dev.zus.network",
"zbox_app_type": "vult",
"sharder_consensous": 2
}
62 changes: 62 additions & 0 deletions winsdk/demo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

Check failure on line 1 in winsdk/demo/main.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/0chain/gosdk/winsdk/demo

// #cgo LDFLAGS: -L. -lzcn.windows
// #include "zcn.windows.h"
import "C"

import (
"fmt"
"os"
)

func main() {

buf, err := os.ReadFile("./config.json")
if err != nil {
panic(err)
}
configJson := C.CString(string(buf))
buf, err = os.ReadFile("./client.json")
if err != nil {
panic(err)
}
clientJson := C.CString(string(buf))
fmt.Println(clientJson)
C.InitSDKs(configJson)
C.InitWallet(clientJson)

// caution: make sure that this allocation exists in wallet
allocID := "f4d07362499b2bcfaccbb3a69fdb9642c5b004d08277e04e4359659989d68fd6"

GetAllocation(allocID)
UploadFile(allocID)
CreateFolder(allocID)

}

// GetAllocation gets an allocation
func GetAllocation(allocID string) {
alloc := C.GetAllocation(C.CString(allocID))
fmt.Println(C.GoString(alloc))
}

// UploadFile uploads a file to the specified allocation
func UploadFile(allocID string) {
buf, err := os.ReadFile("./upload.json")
if err != nil {
panic(err)
}

C.BulkUpload(C.CString(allocID), C.CString(string(buf)))
}

// CreateFolder creates a folder in the specifed allocation
func CreateFolder(allocID string) {
buf, err := os.ReadFile("./multi.json")
if err != nil {
panic(err)
}

fmt.Println("started multiOps", allocID, string(buf))
C.MultiOperation(C.CString(allocID), C.CString(string(buf)))
}
6 changes: 6 additions & 0 deletions winsdk/demo/multi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"operationType": "createdir",
"remotePath": "/testfolder"
}
]
12 changes: 12 additions & 0 deletions winsdk/demo/upload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"Name": "a.txt",
"Path": "a.txt",
"ThumbnailPath": "a.txt",
"RemotePath": "/",
"Encrypt": false,
"IsUpdate": false,
"ChunkNumber": 0,
"IsWebstreaming": false
}
]