@ -18,7 +18,7 @@ import (
"github.com/tjfoc/gmsm/sm2"
"golang.org/x/sync/errgroup"
"go. fusiongalaxy.cn /bdware/bdcontract-client/sm2util"
"go. yandata.net /bdware/bdcontract-client/sm2util"
)
type HttpCOptions struct {
@ -36,10 +36,20 @@ type Client struct {
func NewClient (
baseUrl string ,
priv * sm2 . PrivateKey ,
pub * sm2 . PublicKey ,
priv Str string ,
pub Str string ,
opt HttpCOptions ,
) ( * Client , error ) {
pub , err := sm2util . ParsePublicKey ( pubStr )
if err != nil {
return nil , err
}
priv , err := sm2util . ParsePrivateKey ( privStr , pub )
if err != nil {
return nil , err
}
pubHex , err := sm2util . CheckSm2KeyPair ( priv , pub )
if err != nil {
return nil , err
@ -61,27 +71,27 @@ func NewClient(
// RequestWithSignature
// @Description 发送带有签名的请求
// @Param c 客户端
// @Param path 请求路径
// @Param http 请求方法(GET | POST)
// @Param result 接收请求返回结果的结构体指针
// @Param body 请求体( 尽在method为POST时使用)
// @Param priv 请求私钥
// @Param pub 请求公钥
func ( c * Client ) RequestWithSignature (
func RequestWithSignature [ T any ] (
c * Client ,
path string ,
method string ,
result any ,
body map [ string ] interface { } ,
priv * sm2 . PrivateKey ,
pub * sm2 . PublicKey ,
) ( response HttpResponse [ any ] , err error ) {
response = HttpResponse [ any ] {
) ( response * HttpResponse [ T ] , err error ) {
response = & HttpResponse [ T ] {
Status : 0 ,
}
var pubHex string
if priv != nil {
var err error
pubHex , err = sm2util . CheckSm2KeyPair ( priv , pub )
if err != nil {
return response , err
@ -151,13 +161,15 @@ func (c *Client) RequestWithSignature(
return response , nil
}
err = json . Unmarshal ( bodyBytes , result )
var result T
err = json . Unmarshal ( bodyBytes , & result )
// 如果bodyBytes解析失败直接将信息保存到ErrData
if err != nil {
response . ErrData = string ( bodyBytes )
return response , nil
}
response . Data = result
response . Status = resp . StatusCode
return response , nil
}
@ -195,60 +207,45 @@ func retry[T any](fn func() (T, error)) (T, error) {
return zero , lastErr
}
func genHttpResponse [ D any ] ( data D , response * HttpResponse [ any ] , err error ) ( * HttpResponse [ D ] , error ) {
return & HttpResponse [ D ] {
Data : data ,
Status : response . Status ,
ErrData : response . ErrData ,
} , err
}
// Ping https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id15
func ( c * Client ) Ping ( ) ( * HttpResponse [ PingResponse ] , error ) {
func Ping ( c * Client ) ( * HttpResponse [ PingResponse ] , error ) {
return retry ( func ( ) ( * HttpResponse [ PingResponse ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ PingResponse ] (
c ,
"/SCManager?action=ping" ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ PingResponse ] ( result , & resp , err )
} )
}
// StartContract TODO 未跑通
// StartContract 启动合约
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id60
func ( c * Client ) StartContract ( code string ) ( * HttpResponse [ any ] , error ) {
func StartContract ( c * Client , code string ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : { "startContract" } ,
"script" : { code } ,
}
path := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
path ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// StartContractByYPK TODO 待测试
// StartContractByYPK 启动合约
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id13
func ( c * Client ) StartContractByYPK ( isPrivate bool , path string , script string ) ( * HttpResponse [ any ] , error ) {
func StartContractByYPK ( c * Client , isPrivate bool , path string , script string ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "startContractByYPK" } ,
"script" : [ ] string { script } ,
@ -261,29 +258,27 @@ func (c *Client) StartContractByYPK(isPrivate bool, path string, script string)
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ExecuteContract 调用合约
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id69
func ( c * Client ) ExecuteContract (
func ExecuteContract [ T any ] (
c * Client ,
contractID string ,
operation string ,
arg string ,
arg any ,
withDynamicAnalysis bool ,
withSignature bool ,
) ( * HttpResponse [ ExecuteContractResponse [ any ] ] , error ) {
) ( * HttpResponse [ ExecuteContractResponse [ T ] ] , error ) {
body := map [ string ] any {
"action" : "executeContract" ,
"contractID" : contractID ,
@ -293,29 +288,38 @@ func (c *Client) ExecuteContract(
}
if withSignature {
body [ "signature" ] = c . Sign ( contractID + "|" + operation + "|" + arg + "|" + c . pubHex , nil , nil )
argStr := ""
if v , ok := arg . ( string ) ; ok {
argStr = v
} else {
v , err := json . Marshal ( arg )
if err != nil {
return nil , fmt . Errorf ( "arg %v marshal err" , arg )
}
argStr = string ( v )
}
body [ "signature" ] = c . Sign ( contractID + "|" + operation + "|" + argStr + "|" + c . pubHex , nil , nil )
body [ "pubkey" ] = c . pubHex
}
return retry ( func ( ) ( * HttpResponse [ ExecuteContractResponse [ any ] ] , error ) {
result := ExecuteContractResponse [ any ] { }
resp , err := c . RequestWithSignature (
return retry ( func ( ) ( * HttpResponse [ ExecuteContractResponse [ T ] ] , error ) {
return RequestWithSignature [ ExecuteContractResponse [ T ] ] (
c ,
"/SCManager" ,
"POST" ,
& result ,
body ,
nil ,
nil ,
)
return genHttpResponse [ ExecuteContractResponse [ any ] ] ( result , & resp , err )
} )
}
// KillContractProcess TODO 待测试
// KillContractProcess 停止合约
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id122
func ( c * Client ) KillContractProcess ( contractID string , requestID string ) ( * HttpResponse [ any ] , error ) {
func KillContractProcess ( c * Client , contractID string , requestID string ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "killContractProcess" } ,
"id" : [ ] string { contractID } ,
@ -328,24 +332,22 @@ func (c *Client) KillContractProcess(contractID string, requestID string) (*Http
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// KillAllContract TODO 待测试
// KillAllContract 停止所有合约
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id131
func ( c * Client ) KillAllContract ( ) ( * HttpResponse [ any ] , error ) {
func KillAllContract ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "killAllContract" } ,
}
@ -353,24 +355,22 @@ func (c *Client) KillAllContract() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ApplyNodeRole TODO 待测试
// ApplyNodeRole 申请角色
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
func ( c * Client ) ApplyNodeRole ( role string ) ( * HttpResponse [ any ] , error ) {
func ApplyNodeRole ( c * Client , role string ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "applyNodeRole" } ,
"role" : [ ] string { role } ,
@ -379,24 +379,23 @@ func (c *Client) ApplyNodeRole(role string) (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// AuthNodeRole TODO 待测试
// AuthNodeRole 授权角色
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
func ( c * Client ) AuthNodeRole (
func AuthNodeRole (
c * Client ,
isAccept bool ,
authorizedPubKey string ,
priv * sm2 . PrivateKey ,
@ -411,24 +410,21 @@ func (c *Client) AuthNodeRole(
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
priv ,
pub ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// DistributeContract TODO 待测试, 用sse获取问题未解决! ! !
// 分发合约项目
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
//func (c *Client) DistributeContract(
//func DistributeContract(
// nodeIDs string,
// projectName string,
// isPrivate bool,
@ -444,7 +440,7 @@ func (c *Client) AuthNodeRole(
//
// return retry(func() (*HttpResponse[any], error) {
// result := PingResponse{}
// re sp, err := c. RequestWithSignature(
// re turn RequestWithSignature(
// httpPath,
// "GET",
// &result,
@ -458,7 +454,8 @@ func (c *Client) AuthNodeRole(
//}
// SaveFile TODO 待测试
func ( c * Client ) SaveFile (
func SaveFile (
c * Client ,
content string ,
isAppend bool ,
isPrivate bool ,
@ -475,22 +472,21 @@ func (c *Client) SaveFile(
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ListProjectPermission TODO 待测试
func ( c * Client ) ListProjectPermission (
func ListProjectPermission (
c * Client ,
isPrivate bool ,
path string ,
) ( * HttpResponse [ any ] , error ) {
@ -503,22 +499,20 @@ func (c *Client) ListProjectPermission(
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// StartContractMultiPoint TODO 待测试
func ( c * Client ) StartContractMultiPoint (
func StartContractMultiPoint (
c * Client ,
peersID string ,
contractType int ,
selectUnitNum int ,
@ -539,24 +533,21 @@ func (c *Client) StartContractMultiPoint(
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// LoadNodeConfig TODO 待测试
// 获取节点配置信息
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id497
func ( c * Client ) LoadNodeConfig ( ) ( * HttpResponse [ any ] , error ) {
func LoadNodeConfig ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "loadNodeConfig" } ,
}
@ -564,17 +555,14 @@ func (c *Client) LoadNodeConfig() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
@ -582,7 +570,7 @@ func (c *Client) LoadNodeConfig() (*HttpResponse[any], error) {
// 修改节点配置
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id504
// @Param key {licence, projectDir, yjsPath, dataChain, doipConfig, nodeCenter, nodeName, masterAddress, resetNodeCenterWS}
func ( c * Client ) UpdateConfig ( key string , val string ) ( * HttpResponse [ any ] , error ) {
func UpdateConfig ( c * Client , key string , val string ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "updateConfig" } ,
"key" : [ ] string { key } ,
@ -592,23 +580,20 @@ func (c *Client) UpdateConfig(key string, val string) (*HttpResponse[any], error
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ResetNodeManager TODO 待测试
// 设置pubkey为node manager
func ( c * Client ) ResetNodeManager ( ) ( * HttpResponse [ any ] , error ) {
func ResetNodeManager ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "resetNodeManager" } ,
}
@ -616,23 +601,20 @@ func (c *Client) ResetNodeManager() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// LockEdit TODO 待测试
// 锁定某个用户的的私有目录编辑功能
func ( c * Client ) LockEdit ( ) ( * HttpResponse [ any ] , error ) {
func LockEdit ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "lockEdit" } ,
}
@ -640,23 +622,20 @@ func (c *Client) LockEdit() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// UnlockEdit TODO 待测试
// 解锁某个用户的的私有目录编辑功能
func ( c * Client ) UnlockEdit ( ) ( * HttpResponse [ any ] , error ) {
func UnlockEdit ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "unlockEdit" } ,
}
@ -664,22 +643,19 @@ func (c *Client) UnlockEdit() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// AddNode TODO 待测试
func ( c * Client ) AddNode ( nodePubKey string ) ( * HttpResponse [ any ] , error ) {
func AddNode ( c * Client , nodePubKey string ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "addNode" } ,
"nodePubKey" : [ ] string { nodePubKey } ,
@ -688,23 +664,20 @@ func (c *Client) AddNode(nodePubKey string) (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ApplyRole TODO 待测试
// 申请角色
func ( c * Client ) ApplyRole ( role string ) ( * HttpResponse [ any ] , error ) {
func ApplyRole ( c * Client , role string ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "applyRole" } ,
"role" : [ ] string { role } ,
@ -713,22 +686,19 @@ func (c *Client) ApplyRole(role string) (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// AuthNodeManager TODO 待测试
func ( c * Client ) AuthNodeManager ( isAccept bool , authorizedPubKey string ) ( * HttpResponse [ any ] , error ) {
func AuthNodeManager ( c * Client , isAccept bool , authorizedPubKey string ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "authNodeManager" } ,
"isAccept" : [ ] string { strconv . FormatBool ( isAccept ) } ,
@ -738,22 +708,19 @@ func (c *Client) AuthNodeManager(isAccept bool, authorizedPubKey string) (*HttpR
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ListAllUsers TODO 待测试
func ( c * Client ) ListAllUsers ( ) ( * HttpResponse [ any ] , error ) {
func ListAllUsers ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "listAllUsers" } ,
}
@ -761,22 +728,19 @@ func (c *Client) ListAllUsers() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ListNodes TODO 待测试
func ( c * Client ) ListNodes ( ) ( * HttpResponse [ any ] , error ) {
func ListNodes ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "listNodes" } ,
}
@ -784,24 +748,22 @@ func (c *Client) ListNodes() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// CreateTrustUnit TODO 待测试
// 建立可信执行集群
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id664
func ( c * Client ) CreateTrustUnit (
func CreateTrustUnit (
c * Client ,
data [ ] struct {
nodeName string
pubkey string
@ -818,24 +780,21 @@ func (c *Client) CreateTrustUnit(
}
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
"/SCManager" ,
"POST" ,
& result ,
body ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ListTrustUnits TODO 待测试
// 查看可信执行集群列表
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id657
func ( c * Client ) ListTrustUnits ( ) ( * HttpResponse [ any ] , error ) {
func ListTrustUnits ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "listTrustUnits" } ,
}
@ -843,24 +802,21 @@ func (c *Client) ListTrustUnits() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// ListContractProcess TODO 待测试
// 查询合约进程
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id444
func ( c * Client ) ListContractProcess ( ) ( * HttpResponse [ any ] , error ) {
func ListContractProcess ( c * Client ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "listContractProcess" } ,
}
@ -868,24 +824,21 @@ func (c *Client) ListContractProcess() (*HttpResponse[any], error) {
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
// DownloadContract TODO 待测试
// 下载合约项目
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id25
func ( c * Client ) DownloadContract ( projectName string , isPrivate bool , timestamp int ) ( * HttpResponse [ any ] , error ) {
func DownloadContract ( c * Client , projectName string , isPrivate bool , timestamp int ) ( * HttpResponse [ any ] , error ) {
params := url . Values {
"action" : [ ] string { "downloadContract" } ,
"projectName" : [ ] string { projectName } ,
@ -896,17 +849,14 @@ func (c *Client) DownloadContract(projectName string, isPrivate bool, timestamp
httpPath := fmt . Sprintf ( "/SCManager?%s" , params . Encode ( ) )
return retry ( func ( ) ( * HttpResponse [ any ] , error ) {
result := PingResponse { }
resp , err := c . RequestWithSignature (
return RequestWithSignature [ any ] (
c ,
httpPath ,
"GET" ,
& result ,
nil ,
nil ,
nil ,
)
return genHttpResponse [ any ] ( result , & resp , err )
} )
}
@ -920,8 +870,8 @@ func (c *Client) DownloadContract(projectName string, isPrivate bool, timestamp
// // 配置中心节点时使用
// LHSProxyAddress string
// }
func ( c * Client ) ConfigNode ( arg map [ string ] string ) bool {
res , err := c . ResetNodeManager ( )
func ConfigNode ( c * Client , arg map [ string ] string ) bool {
res , err := ResetNodeManager ( c )
if err != nil || res . Status == 0 {
return false
@ -930,7 +880,7 @@ func (c *Client) ConfigNode(arg map[string]string) bool {
eg := errgroup . Group { }
for key , value := range arg {
eg . Go ( func ( ) error {
res , err = c . UpdateConfig ( key , value )
res , err = UpdateConfig ( c , key , value )
if err != nil {
return err
}
@ -945,7 +895,7 @@ func (c *Client) ConfigNode(arg map[string]string) bool {
for _ , value := range [ ] string { "ContractProvider" , "ContractUser" , "ContractInstanceManager" } {
eg . Go ( func ( ) error {
res , err = c . ApplyNodeRole ( value )
res , err = ApplyNodeRole ( c , value )
if err != nil {
return err
}
@ -959,7 +909,7 @@ func (c *Client) ConfigNode(arg map[string]string) bool {
}
eg . Go ( func ( ) error {
res , err = c . AuthNodeRole ( true , c . pubHex , nil , nil )
res , err = AuthNodeRole ( c , true , c . pubHex , nil , nil )
if err != nil {
return err
}
@ -976,7 +926,7 @@ func (c *Client) ConfigNode(arg map[string]string) bool {
return false
}
res , err = c . LoadNodeConfig ( )
res , err = LoadNodeConfig ( c )
if err != nil || res . Status == 0 {
return false
}