refactor: remove sdk-go dir
This commit is contained in:
1000
client/client.go
Normal file
1000
client/client.go
Normal file
File diff suppressed because it is too large
Load Diff
113
client/client_test.go
Normal file
113
client/client_test.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.fusiongalaxy.cn/bdware/bdcontract-client/sm2util"
|
||||
)
|
||||
|
||||
func TestStruct(t *testing.T) {
|
||||
type a struct {
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
b := &a{age: 1}
|
||||
|
||||
t.Log(b.age)
|
||||
t.Log(b.name == "")
|
||||
}
|
||||
|
||||
func genClient() (*Client, error) {
|
||||
url := "https://cpnode.demo.internetapi.cn/api/ctrlproxy/SCIDE"
|
||||
|
||||
pub, err := sm2util.ParsePublicKey("04153ad2d70e67741e0fc33e0c92c702e2afba2480dbea73d23fd02a3ce3a1b69979a7006a8e045f8836ae4797a8fe426823d7ad3450817e794948c8e47b60b711")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
priv, err := sm2util.ParsePrivateKey("31672b434458fdb6b854e64ededeb51305bc4d0bd258a5276ccb9bc86f7c03f6", pub)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client, err := NewClient(url, priv, pub, HttpCOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
client, err := genClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
t.Log(client)
|
||||
}
|
||||
|
||||
func TestClient_Ping(t *testing.T) {
|
||||
client, err := genClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
resp, err := client.Ping()
|
||||
if err != nil {
|
||||
t.Log(resp.Status)
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
t.Log(resp.Data, resp.Status)
|
||||
}
|
||||
|
||||
func TestClient_StartContract(t *testing.T) {
|
||||
client, err := genClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
resp, err := client.StartContract("contract TestContract {}")
|
||||
|
||||
if err != nil {
|
||||
t.Log(resp)
|
||||
return
|
||||
}
|
||||
|
||||
t.Log(resp)
|
||||
}
|
||||
|
||||
func TestClient_ExecuteContract(t *testing.T) {
|
||||
client, err := genClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
resp, err := client.ExecuteContract("ShanxiControlProxy", "listRepository", "", false, true)
|
||||
|
||||
if err != nil {
|
||||
t.Log(resp)
|
||||
return
|
||||
}
|
||||
|
||||
t.Log(resp)
|
||||
}
|
||||
|
||||
func TestClient_LoadNodeConfig(t *testing.T) {
|
||||
client, err := genClient()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
config, err := client.LoadNodeConfig()
|
||||
if err != nil {
|
||||
t.Log(config)
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
t.Log(config)
|
||||
}
|
||||
129
client/dto.go
Normal file
129
client/dto.go
Normal file
@@ -0,0 +1,129 @@
|
||||
package client
|
||||
|
||||
type HttpResponse[D any] struct {
|
||||
Data D `json:"data"`
|
||||
ErrData string `json:"errData"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
// ClientResponse represents a generic response structure
|
||||
type ClientResponse[T any] struct {
|
||||
NeedSeq bool `json:"needSeq,omitempty"`
|
||||
Seq int `json:"seq,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Result struct {
|
||||
Data T `json:"data,omitempty"`
|
||||
Count int `json:"count,omitempty"`
|
||||
Code int `json:"code,omitempty"`
|
||||
} `json:"result,omitempty"`
|
||||
IsInsnLimit bool `json:"isInsnLimit,omitempty"`
|
||||
TotalGas int `json:"totalGas,omitempty"`
|
||||
ExecutionGas int `json:"executionGas,omitempty"`
|
||||
ExtraGas int `json:"extraGas,omitempty"`
|
||||
Size int `json:"size,omitempty"`
|
||||
EventRelated bool `json:"eventRelated,omitempty"`
|
||||
ResponseID string `json:"responseID,omitempty"`
|
||||
Action string `json:"action,omitempty"`
|
||||
ExecuteTime string `json:"executeTime,omitempty"`
|
||||
}
|
||||
|
||||
// PingResponse is a specific response type for ping operations
|
||||
type PingResponse struct {
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
// SaveFileRequest represents the request structure for saving files
|
||||
type SaveFileRequest struct {
|
||||
Content string `json:"content"`
|
||||
IsAppend bool `json:"isAppend"`
|
||||
IsPrivate bool `json:"isPrivate"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
// ListProjectPermissionRequest represents the request for listing project permissions
|
||||
type ListProjectPermissionRequest struct {
|
||||
IsPrivate bool `json:"isPrivate"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
// ListProjectPermissionResponseData contains permission response data
|
||||
type ListProjectPermissionResponseData struct {
|
||||
Permissions []string `json:"permissions"`
|
||||
YPK string `json:"ypk"`
|
||||
}
|
||||
|
||||
// StartContractByYpkRequest represents the request for starting a contract
|
||||
type StartContractByYpkRequest struct {
|
||||
IsPrivate bool `json:"isPrivate"`
|
||||
Path string `json:"path"`
|
||||
Script string `json:"script"`
|
||||
}
|
||||
|
||||
// ListAllUsersResponseDataListItem represents a key-value pair
|
||||
type ListAllUsersResponseDataListItem struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// ListAllUsersResponseData contains user listing response data
|
||||
type ListAllUsersResponseData struct {
|
||||
KV []ListAllUsersResponseDataListItem `json:"kv"`
|
||||
Time []ListAllUsersResponseDataListItem `json:"time"`
|
||||
}
|
||||
|
||||
// OnlineContractsItem represents an online contract
|
||||
type OnlineContractsItem struct {
|
||||
ContractID string `json:"contractID"`
|
||||
ContractName string `json:"contractName"`
|
||||
IsMaster bool `json:"isMaster"`
|
||||
Type string `json:"type"`
|
||||
YjsType string `json:"yjsType"`
|
||||
Extra map[string]interface{} `json:"-"`
|
||||
}
|
||||
|
||||
// OnlineItem represents an online node
|
||||
type OnlineItem struct {
|
||||
CIManager string `json:"cimanager"`
|
||||
ContractVersion int `json:"contractVersion"`
|
||||
Events int `json:"events"`
|
||||
IPPort string `json:"ipPort"`
|
||||
MasterAddress string `json:"masterAddress"`
|
||||
NodeName string `json:"nodeName"`
|
||||
PeerID string `json:"peerID"`
|
||||
PubKey string `json:"pubKey"`
|
||||
Contracts []OnlineContractsItem `json:"contracts"`
|
||||
}
|
||||
|
||||
// ListNodesResponse represents the response for listing nodes
|
||||
type ListNodesResponse struct {
|
||||
Action string `json:"action"`
|
||||
Offline []string `json:"offline"`
|
||||
Online []OnlineItem `json:"online"`
|
||||
}
|
||||
|
||||
// DistributeContractResponse represents the response for contract distribution
|
||||
type DistributeContractResponse struct {
|
||||
Action string `json:"action"`
|
||||
Progress string `json:"progress"`
|
||||
}
|
||||
|
||||
// ExecuteContractResponse represents the response from contract execution
|
||||
type ExecuteContractResponse[T any] struct {
|
||||
ClientResponse[T]
|
||||
}
|
||||
|
||||
// ConfigNodeArgs represents configuration arguments for a node
|
||||
type ConfigNodeArgs struct {
|
||||
NodeName string `json:"nodeName,omitempty"`
|
||||
DataChain string `json:"dataChain,omitempty"`
|
||||
MasterAddress string `json:"masterAddress,omitempty"`
|
||||
NodeCenter string `json:"nodeCenter,omitempty"`
|
||||
LHSProxyAddress string `json:"LHSProxyAddress,omitempty"`
|
||||
ExtraConfig map[string]string `json:"-"`
|
||||
}
|
||||
|
||||
// LoadNodeConfigResponseData represents the response data for node configuration
|
||||
type LoadNodeConfigResponseData struct {
|
||||
DoipConfig string `json:"doipConfig"`
|
||||
ExtraData map[string]string `json:"-"`
|
||||
}
|
||||
Reference in New Issue
Block a user