...
|
...
|
@@ -15,10 +15,11 @@ import ( |
|
|
|
|
|
type (
|
|
|
BSNBlockChain struct {
|
|
|
PublicPem []byte
|
|
|
PrivatePem []byte
|
|
|
PublicKey string
|
|
|
Host string
|
|
|
PublicPem []byte
|
|
|
PrivatePem []byte
|
|
|
PublicKey string
|
|
|
Host string
|
|
|
EnableDebugLog bool
|
|
|
}
|
|
|
UpToChainRequest struct {
|
|
|
// 上链数据的数据库、数据表等的标识值 (非必填)
|
...
|
...
|
@@ -47,7 +48,7 @@ type ( |
|
|
// type为1或者3时必填
|
|
|
TsTxId string `json:"tsTxId,omitempty"`
|
|
|
// type为2时必填
|
|
|
InnerPrimaryKey string `json:"innerPrimaryKey,omitempty"`
|
|
|
IssueId string `json:"issueId,omitempty"`
|
|
|
// type为3时必填
|
|
|
Value string `json:"value,omitempty"`
|
|
|
// 当type=1或者2必填,为false只显示密文,为true溯源才会显示原文
|
...
|
...
|
@@ -70,8 +71,7 @@ func (c *BSNBlockChain) UpToChain(options *UpToChainOptions) (*UpToChainResponse |
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
data, _ := httputil.DumpRequest(req.GetRequest(), true)
|
|
|
fmt.Println(string(data))
|
|
|
|
|
|
var upToChainResponse UpToChainResponse
|
|
|
_, err = c.HandlerResponse(req, &upToChainResponse)
|
|
|
|
...
|
...
|
@@ -84,8 +84,6 @@ func (c *BSNBlockChain) GetToken(options *GetTokenRequest) (*GetTokenResponse, e |
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
data, _ := httputil.DumpRequest(req.GetRequest(), true)
|
|
|
fmt.Println(string(data))
|
|
|
var getTokenResponse = GetTokenResponse{}
|
|
|
_, err = c.HandlerResponse(req, &getTokenResponse)
|
|
|
return &getTokenResponse, err
|
...
|
...
|
@@ -130,12 +128,15 @@ func (c *BSNBlockChain) MakeRequest(obj interface{}, action string, signAction, |
|
|
if httpMethod == http.MethodPost || httpMethod == http.MethodPut {
|
|
|
req.JSONBody(obj)
|
|
|
}
|
|
|
if c.EnableDebugLog {
|
|
|
data, _ := httputil.DumpRequest(req.GetRequest(), true)
|
|
|
fmt.Println(string(data))
|
|
|
}
|
|
|
return req, nil
|
|
|
}
|
|
|
|
|
|
func (c *BSNBlockChain) HandlerResponse(req *httplib.BeegoHTTPRequest, value interface{}) (*Response, error) {
|
|
|
response := &Response{}
|
|
|
//req.DumpBody(true)
|
|
|
data, err := req.Bytes()
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -151,6 +152,9 @@ func (c *BSNBlockChain) HandlerResponse(req *httplib.BeegoHTTPRequest, value int |
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
if c.EnableDebugLog {
|
|
|
fmt.Println("\nHttp Response-> \n", string(data))
|
|
|
}
|
|
|
if response.Code != 0 {
|
|
|
return nil, fmt.Errorf("upchain code:%v msg:%v", response.Code, response.Message)
|
|
|
}
|
...
|
...
|
|