基于 Golang 语言的 TrustSQL SDK
该 SDK 实现了底层密钥对生成、地址生成、签名/验签等基础功能,并对 TrustSQL 提供的三类(信息共享/身份管理) API 接口进行了封装。
SDK 基础命令
SDK API 接口
下列示例演示了该 SDK 的基本使用方法。
func SendToTrustSQL(content map[string]interface{}) (*tsiss.IssAppendResponse, error) {
privateKey := "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
client, _ := trustsql.NewClient(privateKey)
client.SetIssRequestTimeout(5 * time.Second)
//testURI := ""
//client.SetAppendIssURI(testURI)
accountAddr := client.GetAddrByPubkey()
pubKey := client.GetPublicKey()
issAppend := &tsiss.IssAppend{
Version: "1.0",
SignType: "ECDSA",
MchID: "gbxxxxxxxxxxxxxxx",
//MchSign: "",
Account: string(accountAddr),
CommitTime: time.Now().Format("2006-01-02 15:04:05"),
//Content: map[string]interface{}{"c": "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"},
Content: content,
InfoKey: bson.NewObjectId().Hex(),
//InfoKey: "1242123jjj",
InfoVersion: "1",
State: "0",
Notes: map[string]interface{}{"notes": "comments"},
PublicKey: pubKey,
Sign: "",
ChainID: "ch_tencent_test",
LedgerID: "ld_tencent_iss",
}
signStr, err := client.GetIssSignStr(issAppend)
if err != nil {
fmt.Printf("get issSignStr error: %s\n", err)
return nil, err
}
issAppend.Sign = client.SignString(signStr, true)
appendRes, err := client.AppendIss(issAppend)
if err != nil {
fmt.Printf("append error: %s\n", err)
return nil, err
}
//fmt.Printf("appendRes: %+v\n", appendRes)
return appendRes, nil
}
GoTrustSQL is MIT licensed. See the included LICENSE file for more details.