package zxsdk import ( "github.com/google/uuid" "net/http" "strconv" "wallet_sdk" "zxsdk/constant" "zxsdk/tools" ) type ZxChainClient struct { secretId string secretKey string privateKey string publicKey string addr string httpClient *http.Client } func NewZxChainClient(secretId, secretKey, privateKey string) (*ZxChainClient, error) { if secretId == "" { return nil, constant.SECRET_ID_EMPTY_ERROR } if secretKey == "" { return nil, constant.SECRET_KEY_EMPTY_ERROR } if privateKey == "" { return nil, constant.PRIVATE_KEY_FORMAT_ERROR } publicKey, err := wallet_sdk.PriKey2PubKey(privateKey) if err != nil { return nil, constant.PRIVATE_KEY_FORMAT_ERROR } addr, _ := wallet_sdk.PubKey2Address(publicKey) return &ZxChainClient{ secretId: secretId, secretKey: secretKey, publicKey: publicKey, privateKey: privateKey, addr: addr, httpClient: tools.DefaultHttpClient, }, nil } func (zx ZxChainClient) makeHeader() map[string]string { apiSignData, _ := wallet_sdk.GenerateApiSign(zx.secretId, zx.secretKey) header := map[string]string{ "Secret-Id": zx.secretId, "Signature": apiSignData.Signature, "Signature-Time": apiSignData.SignatureTime, "Nonce": strconv.Itoa(apiSignData.Nonce), constant.TraceKey: uuid.New().String(), } return header } func (zx ZxChainClient) SetHttpClient(client *http.Client) { zx.httpClient = client }