diff --git a/client.go b/client.go index eb827c1..cfe3bea 100644 --- a/client.go +++ b/client.go @@ -103,7 +103,7 @@ func (client *Client) executeAsynchronously(data interface{}) (*TONResult, error num := 0 for result == nil { if num >= DefaultRetries { - return &TONResult{}, fmt.Errorf("Client.executeAsynchronously: exided limit of retries to get json response from TON C`s lib. ") + return &TONResult{}, fmt.Errorf("Client.executeAsynchronously: exceed limit of retries to get json response from TON C`s lib. ") } time.Sleep(1 * time.Second) result = C.tonlib_client_json_receive(client.client, DEFAULT_TIMEOUT) diff --git a/cmd/tongo/createPrivateKey.go b/cmd/tongo/createPrivateKey.go index 261157d..be9a7db 100644 --- a/cmd/tongo/createPrivateKey.go +++ b/cmd/tongo/createPrivateKey.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "log" "os" diff --git a/cmd/tongo/deletePrivateKey.go b/cmd/tongo/deletePrivateKey.go index 8db1937..ceba5e4 100644 --- a/cmd/tongo/deletePrivateKey.go +++ b/cmd/tongo/deletePrivateKey.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "os" ) diff --git a/cmd/tongo/estimateFee.go b/cmd/tongo/estimateFee.go index 87ea455..12721a0 100644 --- a/cmd/tongo/estimateFee.go +++ b/cmd/tongo/estimateFee.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "log" "os" diff --git a/cmd/tongo/exportPrivateKey.go b/cmd/tongo/exportPrivateKey.go index b317d42..80a4f40 100644 --- a/cmd/tongo/exportPrivateKey.go +++ b/cmd/tongo/exportPrivateKey.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "os" ) diff --git a/cmd/tongo/main.go b/cmd/tongo/main.go index b9d0390..ab6903e 100644 --- a/cmd/tongo/main.go +++ b/cmd/tongo/main.go @@ -5,7 +5,7 @@ import ( "os" "os/signal" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" ) diff --git a/cmd/tongo/rawAccountState.go b/cmd/tongo/rawAccountState.go index b608d20..99fceac 100644 --- a/cmd/tongo/rawAccountState.go +++ b/cmd/tongo/rawAccountState.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "log" "os" diff --git a/cmd/tongo/sendFile.go b/cmd/tongo/sendFile.go index df1841d..15697da 100644 --- a/cmd/tongo/sendFile.go +++ b/cmd/tongo/sendFile.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "io/ioutil" "os" diff --git a/cmd/tongo/sendGramm.go b/cmd/tongo/sendGramm.go index 8f4aab2..9c2e9c2 100644 --- a/cmd/tongo/sendGramm.go +++ b/cmd/tongo/sendGramm.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "log" "os" diff --git a/cmd/tongo/sendMessage.go b/cmd/tongo/sendMessage.go index 8d14586..fde2479 100644 --- a/cmd/tongo/sendMessage.go +++ b/cmd/tongo/sendMessage.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "os" ) diff --git a/cmd/tongo/transactions.go b/cmd/tongo/transactions.go index 49cee27..091c0d2 100644 --- a/cmd/tongo/transactions.go +++ b/cmd/tongo/transactions.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "log" "os" diff --git a/cmd/tongo/walletAddress.go b/cmd/tongo/walletAddress.go index c841ccf..2e66b61 100644 --- a/cmd/tongo/walletAddress.go +++ b/cmd/tongo/walletAddress.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "os" ) diff --git a/cmd/tongo/walletState.go b/cmd/tongo/walletState.go index cb29ced..1504b00 100644 --- a/cmd/tongo/walletState.go +++ b/cmd/tongo/walletState.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "github.com/spf13/cobra" "os" ) diff --git a/example/send_gram.go b/example/send_gram.go index 87efa07..d2d296a 100644 --- a/example/send_gram.go +++ b/example/send_gram.go @@ -3,7 +3,7 @@ package main import ( "encoding/base64" "fmt" - "github.com/mercuryoio/tonlib-go" + "github.com/varche1/tonlib-go" "log" ) diff --git a/go.mod b/go.mod index 4ad7c88..1610bc0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/mercuryoio/tonlib-go +module github.com/varche1/tonlib-go go 1.13 diff --git a/lib/lib.go b/lib/lib.go index e7aae82..dcd40cf 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -1,6 +1,6 @@ package linux import ( - _ "github.com/mercuryoio/tonlib-go/lib/darwin" - _ "github.com/mercuryoio/tonlib-go/lib/linux" + _ "github.com/varche1/tonlib-go/lib/darwin" + _ "github.com/varche1/tonlib-go/lib/linux" ) diff --git a/lib/linux/libtonlib.a b/lib/linux/libtonlib.a index 736504d..0cd58ec 100644 Binary files a/lib/linux/libtonlib.a and b/lib/linux/libtonlib.a differ diff --git a/lib/linux/libtonlibjson.so b/lib/linux/libtonlibjson.so deleted file mode 100755 index 83674f1..0000000 Binary files a/lib/linux/libtonlibjson.so and /dev/null differ diff --git a/lib/linux/libtonlibjson.so b/lib/linux/libtonlibjson.so new file mode 120000 index 0000000..4c990e8 --- /dev/null +++ b/lib/linux/libtonlibjson.so @@ -0,0 +1 @@ +libtonlibjson.so.0.5 \ No newline at end of file diff --git a/lib/linux/libtonlibjson.so.0.5 b/lib/linux/libtonlibjson.so.0.5 index 83674f1..01f8264 100755 Binary files a/lib/linux/libtonlibjson.so.0.5 and b/lib/linux/libtonlibjson.so.0.5 differ diff --git a/lib/linux/libtonlibjson_private.a b/lib/linux/libtonlibjson_private.a index c68c006..d1e0c12 100644 Binary files a/lib/linux/libtonlibjson_private.a and b/lib/linux/libtonlibjson_private.a differ diff --git a/v2/client.go b/v2/client.go index 5be495a..707e22c 100644 --- a/v2/client.go +++ b/v2/client.go @@ -69,7 +69,9 @@ type TonInitRequest struct { } // NewClient Creates a new instance of TONLib. -func NewClient(tonCnf *TonInitRequest, config Config, timeout int64, clientLogging bool, tonLogging int32) (*Client, error) { +func NewClient(tonCnf *TonInitRequest, config Config, timeout int64, clientLogging bool, + tonLogging int32, +) (*Client, int64, error) { rand.Seed(time.Now().UnixNano()) client := Client{ @@ -84,24 +86,24 @@ func NewClient(tonCnf *TonInitRequest, config Config, timeout int64, clientLoggi // disable ton logs if needed err := client.executeSetLogLevel(tonLogging) if err != nil { - return &client, err + return &client, 0, err } optionsInfo, err := client.Init(tonCnf.Options) if err != nil { - return &client, err + return &client, 0, err } if optionsInfo.tonCommon.Type == "options.info" { - return &client, nil + return &client, int64(optionsInfo.ConfigInfo.DefaultWalletId), nil } if optionsInfo.tonCommon.Type == "error" { - return &client, fmt.Errorf("Error ton client init. Message: %s. ", optionsInfo.tonCommon.Extra) + return &client, 0, fmt.Errorf("Error ton client init. Message: %s. ", optionsInfo.tonCommon.Extra) } - return &client, fmt.Errorf("Error ton client init. ") + return &client, 0, fmt.Errorf("Error ton client init. ") } // disable ton client C lib`s logs -func (client *Client) executeSetLogLevel(logLevel int32) (error) { +func (client *Client) executeSetLogLevel(logLevel int32) error { data := struct { Type string `json:"@type"` NewVerbosityLevel int32 `json:"new_verbosity_level"` @@ -123,13 +125,66 @@ func (client *Client) executeSetLogLevel(logLevel int32) (error) { return nil } -/** -execute ton-lib asynchronously -*/ -func (client *Client) executeAsynchronously(data interface{}) (*TONResult, error) { +func (client *Client) GenerateRequestID() string { + return RandSeq(20) +} + +func (client *Client) receive(maxRetries int, requestID *string) (*TONResult, error) { + attemptWaiting := 1 * time.Second + + if maxRetries <= 0 { + return nil, fmt.Errorf("Client.executeAsynchronously: exceed limit of retries to get json response from TON C`s lib. ") + } + + received := C.tonlib_client_json_receive(client.client, DEFAULT_TIMEOUT) + maxRetries -= 1 + + for received == nil { + fmt.Printf("fetch nothing. Wait for: %s and try again\n", attemptWaiting) + if maxRetries <= 0 { + return nil, fmt.Errorf("Client.executeAsynchronously: exceed limit of retries to get json response from TON C`s lib. ") + } + time.Sleep(attemptWaiting) + + received = C.tonlib_client_json_receive(client.client, DEFAULT_TIMEOUT) + maxRetries -= 1 + } + + res := C.GoString(received) + resB := []byte(res) + + if client.clientLogging { + fmt.Println("fetch data: ", string(resB)) + } + + var response TONResponse + err := json.Unmarshal(resB, &response) + if err != nil { + return nil, err + } + + result := TONResult{Data: response, Raw: resB} + + if requestID != nil && !client.isExtraMatch(result, *requestID) { + fmt.Println("fetched data is not fit by @extra. Try to fetch again") + return client.receive(maxRetries, requestID) + } + + return &result, nil +} + +func (client *Client) receiveAny(maxRetries int) (*TONResult, error) { + return client.receive(maxRetries, nil) +} + +func (client *Client) receiveExactly(maxRetries int, requestID string) (*TONResult, error) { + return client.receive(maxRetries, &requestID) +} + +func (client *Client) send(data interface{}) error { req, err := json.Marshal(data) if err != nil { - return &TONResult{}, err + return err } cs := C.CString(string(req)) defer C.free(unsafe.Pointer(cs)) @@ -138,59 +193,94 @@ func (client *Client) executeAsynchronously(data interface{}) (*TONResult, error fmt.Println("call", string(req)) } C.tonlib_client_json_send(client.client, cs) - result := C.tonlib_client_json_receive(client.client, DEFAULT_TIMEOUT) - num := 0 - for result == nil { - if num >= DefaultRetries { - return &TONResult{}, fmt.Errorf("Client.executeAsynchronously: exided limit of retries to get json response from TON C`s lib. ") - } - time.Sleep(1 * time.Second) - result = C.tonlib_client_json_receive(client.client, DEFAULT_TIMEOUT) - num += 1 + return nil +} + +func (client *Client) isExtraMatch(result TONResult, requestID string) bool { + extra, ok := result.Data["@extra"] + if !ok { + return false } - var updateData TONResponse - res := C.GoString(result) - resB := []byte(res) - err = json.Unmarshal(resB, &updateData) - if client.clientLogging { - fmt.Println("fetch data: ", string(resB)) + if extra != requestID { + return false } - if st, ok := updateData["@type"]; ok && st == "updateSendLiteServerQuery" { - err = json.Unmarshal(resB, &updateData) - if err == nil { - _, err = client.OnLiteServerQueryResult(updateData["data"].([]byte), updateData["id"].(JSONInt64), ) + + return true +} + +func (client *Client) executeAsynchronously(data interface{}, requestID string) (*TONResult, error) { + return client.executeAsynchronouslyCommon(data, requestID, false) +} + +func (client *Client) executeAsynchronouslyExactlyOnce(data interface{}, requestID string) (*TONResult, error) { + return client.executeAsynchronouslyCommon(data, requestID, true) +} + +/** +execute ton-lib asynchronously +*/ +func (client *Client) executeAsynchronouslyCommon(data interface{}, requestID string, exactlyOnce bool) (*TONResult, error) { + if err := client.send(data); err != nil { + return nil, err + } + + result, err := client.receiveAny(DefaultRetries) + if err != nil { + return nil, err + } + + resultType, ok := result.Data["@type"] + if !ok { + return nil, fmt.Errorf("got response invalid struct: field `@type` is undefined") + } + + if resultType == "updateSendLiteServerQuery" { + _, err = client.OnLiteServerQueryResult(result.Data["data"].([]byte), result.Data["id"].(JSONInt64)) + if err != nil { + return nil, err + } + if exactlyOnce { + return nil, fmt.Errorf("can't send to lib more than once [by getting updateSendLiteServerQuery]") } + return client.executeAsynchronouslyCommon(data, requestID, exactlyOnce) } - if st, ok := updateData["@type"]; ok && st == "updateSyncState" { + + if resultType == "updateSyncState" { syncResp := struct { Type string `json:"@type"` SyncState SyncState `json:"sync_state"` }{} - err = json.Unmarshal(resB, &syncResp) + err = json.Unmarshal(result.Raw, &syncResp) if err != nil { - return &TONResult{}, err + return nil, err } if client.clientLogging { - fmt.Println("run sync", updateData) + fmt.Println("run sync", syncResp) } - res, err = client.Sync(syncResp.SyncState) + resultWhileSync, err := client.Sync(syncResp.SyncState, &requestID) if err != nil { - return &TONResult{}, err + return nil, err } - if res != "" { - // parse and return reponse that has been catched while sync - resB := []byte(res) - err = json.Unmarshal(resB, &updateData) - if err != nil { - return &TONResult{}, err - } - return &TONResult{Data: updateData, Raw: resB}, err + + if resultWhileSync != nil && client.isExtraMatch(*resultWhileSync, requestID) { + fmt.Printf("got result while sync: %s\n", resultWhileSync.Raw) + return resultWhileSync, nil + } + + if exactlyOnce { + return nil, fmt.Errorf("can't send to lib more than once [by getting updateSyncState]") } - return client.executeAsynchronously(data) + return client.executeAsynchronouslyCommon(data, requestID, exactlyOnce) } - return &TONResult{Data: updateData, Raw: resB}, err + + if !client.isExtraMatch(*result, requestID) { + fmt.Printf("@extra is not the same: real:%s expected:%s. Skip result: %s\n", result.Data["@extra"], requestID, result.Raw) + return client.receiveExactly(DefaultRetries, requestID) + } + + return result, nil } /** @@ -214,7 +304,7 @@ func (client *Client) Destroy() { } //sync node`s blocks to current -func (client *Client) Sync(syncState SyncState) (string, error) { +func (client *Client) Sync(syncState SyncState, requestID *string) (*TONResult, error) { data := struct { Type string `json:"@type"` SyncState SyncState `json:"sync_state"` @@ -222,64 +312,62 @@ func (client *Client) Sync(syncState SyncState) (string, error) { Type: "sync", SyncState: syncState, } - req, err := json.Marshal(data) - if err != nil { - return "", err + if err := client.send(data); err != nil { + return nil, err } - cs := C.CString(string(req)) - defer C.free(unsafe.Pointer(cs)) - C.tonlib_client_json_send(client.client, cs) + + var meaningfulResult *TONResult + + syncAttempt := 0 for { - result := C.tonlib_client_json_receive(client.client, DEFAULT_TIMEOUT) - for result == nil { - if client.clientLogging { - fmt.Println("empty response. next attempt") - } - time.Sleep(1 * time.Second) - result = C.tonlib_client_json_receive(client.client, DEFAULT_TIMEOUT) + syncAttempt += 1 + + result, err := client.receiveAny(DefaultRetries) + if err != nil { + return nil, err } + syncResp := struct { Type string `json:"@type"` SyncState SyncState `json:"sync_state"` }{} - res := C.GoString(result) - resB := []byte(res) - err = json.Unmarshal(resB, &syncResp) + err = json.Unmarshal(result.Raw, &syncResp) + if err != nil { + return nil, err + } + if client.clientLogging { - fmt.Println("sync result #1: ", res) + fmt.Printf("sync result #%d: %s \n", syncAttempt, result.Raw) } - if err != nil { - return "", err + + if requestID != nil && client.isExtraMatch(*result, *requestID) { + if meaningfulResult != nil { + return nil, fmt.Errorf("Got several fit result while sync. It's unexpected behavior: `%s` ", result.Raw) + } + meaningfulResult = result + fmt.Printf("catch meaningful result while sync: %s \n", result.Raw) + continue } + if syncResp.Type == "error" { - return "", fmt.Errorf("Got an error response from ton: `%s` ", res) + return nil, fmt.Errorf("Got an error response from ton: `%s` ", result.Raw) } + if syncResp.SyncState.Type == "syncStateDone" { - result := C.tonlib_client_json_receive(client.client, DEFAULT_TIMEOUT) - syncResp = struct { - Type string `json:"@type"` - SyncState SyncState `json:"sync_state"` - }{} - res := C.GoString(result) - resB := []byte(res) - err = json.Unmarshal(resB, &syncResp) - if client.clientLogging { - fmt.Println("sync result #2: ", string(resB)) - } - if err != nil { - return "", err - } + break } + if syncResp.Type == "ton.blockIdExt" { - return "", nil + break } + if syncResp.Type == "updateSyncState" { // continue updating continue } - // response on previously not sync request - return res, nil } + + return meaningfulResult, nil } // QueryEstimateFees @@ -287,12 +375,15 @@ func (client *Client) Sync(syncState SyncState) (string, error) { // @param id // @param ignoreChksig func (client *Client) QueryEstimateFees(id int64, ignoreChksig bool) (*QueryFees, error) { + requestID := client.GenerateRequestID() callData := struct { Type string `json:"@type"` + Extra string `json:"@extra"` Id int64 `json:"id"` IgnoreChksig bool `json:"ignore_chksig"` }{ Type: "query.estimateFees", + Extra: requestID, Id: id, IgnoreChksig: ignoreChksig, } @@ -315,7 +406,7 @@ func (client *Client) QueryEstimateFees(id int64, ignoreChksig bool) (*QueryFees go func() { for true { - result, err := client.executeAsynchronously(callData) + result, err := client.executeAsynchronously(callData, requestID) // if timeout reached - close chan and exit exit.Lock() if exit.Exit { @@ -359,7 +450,7 @@ func (client *Client) QueryEstimateFees(id int64, ignoreChksig bool) (*QueryFees } // for now - a few requests may works wrong, cause it some times get respose form previos reqest for a few times -func (client *Client) UpdateTonConnection() (error) { +func (client *Client) UpdateTonConnection() error { _, err := client.Close() if err != nil { return err @@ -420,10 +511,20 @@ func NewKey(publicKey string, secret string) *Key { // InitialAccountState type InitialAccountState interface{ MessageType() string } -type AccountState RawAccountState +type AccountState CommonAccountState type MsgData interface{ MessageType() string } type DnsEntryData string type Action interface{ MessageType() string } type DnsAction Action + +type CommonAccountState struct { + tonCommon + Code string `json:"code"` + Data string `json:"data"` + FrozenHash []byte `json:"frozen_hash"` + PublicKey string `json:"public_key"` + WalletId JSONInt64 `json:"wallet_id"` + Seqno JSONInt64 `json:"seqno"` +} diff --git a/v2/client_test.go b/v2/client_test.go index 240f8cf..a423641 100644 --- a/v2/client_test.go +++ b/v2/client_test.go @@ -33,7 +33,7 @@ func TestClient_NewClient(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("Init client error. ", err) } @@ -54,7 +54,7 @@ func TestClient_CreateNewKey(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("Init client error. ", err) } @@ -87,7 +87,7 @@ func TestClient_DeleteKey(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("Init client error. ", err) } @@ -127,7 +127,7 @@ func TestClient_ExportKey(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("Init client error. ", err) } @@ -174,7 +174,7 @@ func TestClient_ExportPemKey(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("Init client error. ", err) } @@ -221,7 +221,7 @@ func TestClient_RawGetAccountState(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("TestClient_RawGetAccountState Init client error. ", err) } @@ -249,7 +249,7 @@ func TestClient_WalletGetAccountAddress(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("TestClient_WalletGetAccountAddress Init client error. ", err) } @@ -290,7 +290,7 @@ func TestClient_WalletGetAccountState(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("TestClient_WalletGetAccountState Init client error. ", err) } @@ -337,7 +337,7 @@ func TestClient_RawGetTransactions(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("TestClient_RawGetTransactions Init client error. ", err) } @@ -381,7 +381,7 @@ func TestClient_RawCreateAndSendMessage(t *testing.T) { } // create client - cln, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) + cln, _, err := NewClient(&req, Config{}, DefaultTestTimeout, true, 100) if err != nil { t.Fatal("TestClient_RawCreateAndSendMessage Init client error. ", err) } diff --git a/v2/cmd/tongo/createPrivateKey.go b/v2/cmd/tongo/createPrivateKey.go index 9c69c5b..9e144d8 100644 --- a/v2/cmd/tongo/createPrivateKey.go +++ b/v2/cmd/tongo/createPrivateKey.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "log" "os" diff --git a/v2/cmd/tongo/deletePrivateKey.go b/v2/cmd/tongo/deletePrivateKey.go index 9b72694..ba385a8 100644 --- a/v2/cmd/tongo/deletePrivateKey.go +++ b/v2/cmd/tongo/deletePrivateKey.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "os" ) diff --git a/v2/cmd/tongo/estimateFee.go b/v2/cmd/tongo/estimateFee.go index bd0e333..50517a9 100644 --- a/v2/cmd/tongo/estimateFee.go +++ b/v2/cmd/tongo/estimateFee.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "log" "os" diff --git a/v2/cmd/tongo/exportPrivateKey.go b/v2/cmd/tongo/exportPrivateKey.go index 262e5f3..5444568 100644 --- a/v2/cmd/tongo/exportPrivateKey.go +++ b/v2/cmd/tongo/exportPrivateKey.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "os" ) diff --git a/v2/cmd/tongo/main.go b/v2/cmd/tongo/main.go index 338a3eb..5333b17 100644 --- a/v2/cmd/tongo/main.go +++ b/v2/cmd/tongo/main.go @@ -2,7 +2,7 @@ package main import ( "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "os" "os/signal" @@ -27,7 +27,7 @@ func initClient(configPath string) error { *options, } - tonClient, err = tonlib.NewClient(&req, tonlib.Config{}, 10, true, 9) + tonClient, _, err = tonlib.NewClient(&req, tonlib.Config{}, 10, true, 9) if err != nil { err = fmt.Errorf("Init client error: %v. ", err) } diff --git a/v2/cmd/tongo/rawAccountState.go b/v2/cmd/tongo/rawAccountState.go index 67ce8d3..5cb42b2 100644 --- a/v2/cmd/tongo/rawAccountState.go +++ b/v2/cmd/tongo/rawAccountState.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "log" "os" diff --git a/v2/cmd/tongo/runSmcMethod.go b/v2/cmd/tongo/runSmcMethod.go index 1fadbb2..ba5a5c2 100644 --- a/v2/cmd/tongo/runSmcMethod.go +++ b/v2/cmd/tongo/runSmcMethod.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "log" "os" diff --git a/v2/cmd/tongo/sendFile.go b/v2/cmd/tongo/sendFile.go index dcdc509..3919d1e 100644 --- a/v2/cmd/tongo/sendFile.go +++ b/v2/cmd/tongo/sendFile.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "io/ioutil" "os" diff --git a/v2/cmd/tongo/sendGramm.go b/v2/cmd/tongo/sendGramm.go index 6d9cec0..c56b90a 100644 --- a/v2/cmd/tongo/sendGramm.go +++ b/v2/cmd/tongo/sendGramm.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "log" "os" diff --git a/v2/cmd/tongo/sendMessage.go b/v2/cmd/tongo/sendMessage.go index a270712..46aa6c8 100644 --- a/v2/cmd/tongo/sendMessage.go +++ b/v2/cmd/tongo/sendMessage.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "os" ) diff --git a/v2/cmd/tongo/transactions.go b/v2/cmd/tongo/transactions.go index 82ed6b1..8681a3e 100644 --- a/v2/cmd/tongo/transactions.go +++ b/v2/cmd/tongo/transactions.go @@ -4,7 +4,7 @@ import ( "encoding/base64" "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "log" "os" diff --git a/v2/cmd/tongo/walletAddress.go b/v2/cmd/tongo/walletAddress.go index 22ed29e..2921953 100644 --- a/v2/cmd/tongo/walletAddress.go +++ b/v2/cmd/tongo/walletAddress.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "os" ) diff --git a/v2/cmd/tongo/walletState.go b/v2/cmd/tongo/walletState.go index f65d34b..1eb29c6 100644 --- a/v2/cmd/tongo/walletState.go +++ b/v2/cmd/tongo/walletState.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "github.com/spf13/cobra" "os" ) diff --git a/v2/example/send_gram.go b/v2/example/send_gram.go index 1e81fe1..a27870d 100644 --- a/v2/example/send_gram.go +++ b/v2/example/send_gram.go @@ -3,7 +3,7 @@ package main import ( "encoding/base64" "fmt" - tonlib "github.com/mercuryoio/tonlib-go/v2" + tonlib "github.com/varche1/tonlib-go/v2" "log" ) @@ -19,7 +19,7 @@ func main() { "init", *options, } - cln, err := tonlib.NewClient(&req, tonlib.Config{}, 10, true, 9) + cln, _, err := tonlib.NewClient(&req, tonlib.Config{}, 10, true, 9) if err != nil { log.Fatalln("Init client error", err) } diff --git a/v2/go.mod b/v2/go.mod index ec38251..500fae6 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -1,4 +1,4 @@ -module github.com/mercuryoio/tonlib-go/v2 +module github.com/varche1/tonlib-go/v2 go 1.13 diff --git a/v2/lib/lib.go b/v2/lib/lib.go index 05c10e0..b168ecc 100644 --- a/v2/lib/lib.go +++ b/v2/lib/lib.go @@ -1,6 +1,6 @@ package linux import ( - _ "github.com/mercuryoio/tonlib-go/v2/lib/darwin" - _ "github.com/mercuryoio/tonlib-go/v2/lib/linux" + _ "github.com/varche1/tonlib-go/v2/lib/darwin" + _ "github.com/varche1/tonlib-go/v2/lib/linux" ) diff --git a/v2/lib/linux/libtonlib.a b/v2/lib/linux/libtonlib.a index 748da2f..0cd58ec 100644 Binary files a/v2/lib/linux/libtonlib.a and b/v2/lib/linux/libtonlib.a differ diff --git a/v2/lib/linux/libtonlibjson.so b/v2/lib/linux/libtonlibjson.so index c731ad4..01f8264 100755 Binary files a/v2/lib/linux/libtonlibjson.so and b/v2/lib/linux/libtonlibjson.so differ diff --git a/v2/lib/linux/libtonlibjson.so.0.5 b/v2/lib/linux/libtonlibjson.so.0.5 index dc0ae47..01f8264 100755 Binary files a/v2/lib/linux/libtonlibjson.so.0.5 and b/v2/lib/linux/libtonlibjson.so.0.5 differ diff --git a/v2/lib/linux/libtonlibjson_private.a b/v2/lib/linux/libtonlibjson_private.a index 5e31f06..d1e0c12 100644 Binary files a/v2/lib/linux/libtonlibjson_private.a and b/v2/lib/linux/libtonlibjson_private.a differ diff --git a/v2/lib/linux/libtonlibjson_static.a b/v2/lib/linux/libtonlibjson_static.a index ee04d05..f599a3e 100644 Binary files a/v2/lib/linux/libtonlibjson_static.a and b/v2/lib/linux/libtonlibjson_static.a differ diff --git a/v2/methods.go b/v2/methods.go index 0027764..25078e7 100755 --- a/v2/methods.go +++ b/v2/methods.go @@ -8,14 +8,18 @@ import ( // Init // @param options func (client *Client) Init(options Options) (*OptionsInfo, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Options Options `json:"options"` }{ Type: "init", + Extra: requestID, Options: options, }, + requestID, ) if err != nil { @@ -34,12 +38,16 @@ func (client *Client) Init(options Options) (*OptionsInfo, error) { // Close func (client *Client) Close() (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` + Type string `json:"@type"` + Extra string `json:"@extra"` }{ - Type: "close", + Type: "close", + Extra: requestID, }, + requestID, ) if err != nil { @@ -59,14 +67,18 @@ func (client *Client) Close() (*Ok, error) { // OptionsSetConfig // @param config func (client *Client) OptionsSetConfig(config Config) (*OptionsConfigInfo, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Config Config `json:"config"` }{ Type: "options.setConfig", + Extra: requestID, Config: config, }, + requestID, ) if err != nil { @@ -86,14 +98,18 @@ func (client *Client) OptionsSetConfig(config Config) (*OptionsConfigInfo, error // OptionsValidateConfig // @param config func (client *Client) OptionsValidateConfig(config Config) (*OptionsConfigInfo, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Config Config `json:"config"` }{ Type: "options.validateConfig", + Extra: requestID, Config: config, }, + requestID, ) if err != nil { @@ -115,18 +131,22 @@ func (client *Client) OptionsValidateConfig(config Config) (*OptionsConfigInfo, // @param mnemonicPassword // @param randomExtraSeed func (client *Client) CreateNewKey(localPassword SecureBytes, mnemonicPassword SecureBytes, randomExtraSeed SecureBytes) (*Key, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` LocalPassword SecureBytes `json:"local_password"` MnemonicPassword SecureBytes `json:"mnemonic_password"` RandomExtraSeed SecureBytes `json:"random_extra_seed"` }{ Type: "createNewKey", + Extra: requestID, LocalPassword: localPassword, MnemonicPassword: mnemonicPassword, RandomExtraSeed: randomExtraSeed, }, + requestID, ) if err != nil { @@ -146,14 +166,18 @@ func (client *Client) CreateNewKey(localPassword SecureBytes, mnemonicPassword S // DeleteKey // @param key func (client *Client) DeleteKey(key Key) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Key Key `json:"key"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Key Key `json:"key"` }{ - Type: "deleteKey", - Key: key, + Type: "deleteKey", + Extra: requestID, + Key: key, }, + requestID, ) if err != nil { @@ -172,12 +196,16 @@ func (client *Client) DeleteKey(key Key) (*Ok, error) { // DeleteAllKeys func (client *Client) DeleteAllKeys() (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` + Type string `json:"@type"` + Extra string `json:"@extra"` }{ - Type: "deleteAllKeys", + Type: "deleteAllKeys", + Extra: requestID, }, + requestID, ) if err != nil { @@ -197,14 +225,18 @@ func (client *Client) DeleteAllKeys() (*Ok, error) { // ExportKey // @param inputKey func (client *Client) ExportKey(inputKey InputKey) (*ExportedKey, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` InputKey InputKey `json:"input_key"` }{ Type: "exportKey", + Extra: requestID, InputKey: inputKey, }, + requestID, ) if err != nil { @@ -225,16 +257,20 @@ func (client *Client) ExportKey(inputKey InputKey) (*ExportedKey, error) { // @param inputKey // @param keyPassword func (client *Client) ExportPemKey(inputKey InputKey, keyPassword SecureBytes) (*ExportedPemKey, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` InputKey InputKey `json:"input_key"` KeyPassword SecureBytes `json:"key_password"` }{ Type: "exportPemKey", + Extra: requestID, InputKey: inputKey, KeyPassword: keyPassword, }, + requestID, ) if err != nil { @@ -255,16 +291,20 @@ func (client *Client) ExportPemKey(inputKey InputKey, keyPassword SecureBytes) ( // @param inputKey // @param keyPassword func (client *Client) ExportEncryptedKey(inputKey InputKey, keyPassword SecureBytes) (*ExportedEncryptedKey, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` InputKey InputKey `json:"input_key"` KeyPassword SecureBytes `json:"key_password"` }{ Type: "exportEncryptedKey", + Extra: requestID, InputKey: inputKey, KeyPassword: keyPassword, }, + requestID, ) if err != nil { @@ -284,14 +324,18 @@ func (client *Client) ExportEncryptedKey(inputKey InputKey, keyPassword SecureBy // ExportUnencryptedKey // @param inputKey func (client *Client) ExportUnencryptedKey(inputKey InputKey) (*ExportedUnencryptedKey, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` InputKey InputKey `json:"input_key"` }{ Type: "exportUnencryptedKey", + Extra: requestID, InputKey: inputKey, }, + requestID, ) if err != nil { @@ -313,18 +357,22 @@ func (client *Client) ExportUnencryptedKey(inputKey InputKey) (*ExportedUnencryp // @param localPassword // @param mnemonicPassword func (client *Client) ImportKey(exportedKey ExportedKey, localPassword SecureBytes, mnemonicPassword SecureBytes) (*Key, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` ExportedKey ExportedKey `json:"exported_key"` LocalPassword SecureBytes `json:"local_password"` MnemonicPassword SecureBytes `json:"mnemonic_password"` }{ Type: "importKey", + Extra: requestID, ExportedKey: exportedKey, LocalPassword: localPassword, MnemonicPassword: mnemonicPassword, }, + requestID, ) if err != nil { @@ -346,18 +394,22 @@ func (client *Client) ImportKey(exportedKey ExportedKey, localPassword SecureByt // @param keyPassword // @param localPassword func (client *Client) ImportPemKey(exportedKey ExportedPemKey, keyPassword SecureBytes, localPassword SecureBytes) (*Key, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` ExportedKey ExportedPemKey `json:"exported_key"` KeyPassword SecureBytes `json:"key_password"` LocalPassword SecureBytes `json:"local_password"` }{ Type: "importPemKey", + Extra: requestID, ExportedKey: exportedKey, KeyPassword: keyPassword, LocalPassword: localPassword, }, + requestID, ) if err != nil { @@ -379,18 +431,22 @@ func (client *Client) ImportPemKey(exportedKey ExportedPemKey, keyPassword Secur // @param keyPassword // @param localPassword func (client *Client) ImportEncryptedKey(exportedEncryptedKey ExportedEncryptedKey, keyPassword SecureBytes, localPassword SecureBytes) (*Key, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` ExportedEncryptedKey ExportedEncryptedKey `json:"exported_encrypted_key"` KeyPassword SecureBytes `json:"key_password"` LocalPassword SecureBytes `json:"local_password"` }{ Type: "importEncryptedKey", + Extra: requestID, ExportedEncryptedKey: exportedEncryptedKey, KeyPassword: keyPassword, LocalPassword: localPassword, }, + requestID, ) if err != nil { @@ -411,16 +467,20 @@ func (client *Client) ImportEncryptedKey(exportedEncryptedKey ExportedEncryptedK // @param exportedUnencryptedKey // @param localPassword func (client *Client) ImportUnencryptedKey(exportedUnencryptedKey ExportedUnencryptedKey, localPassword SecureBytes) (*Key, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` ExportedUnencryptedKey ExportedUnencryptedKey `json:" exported_unencrypted_key"` LocalPassword SecureBytes `json:"local_password"` }{ Type: "importUnencryptedKey", + Extra: requestID, ExportedUnencryptedKey: exportedUnencryptedKey, LocalPassword: localPassword, }, + requestID, ) if err != nil { @@ -441,16 +501,20 @@ func (client *Client) ImportUnencryptedKey(exportedUnencryptedKey ExportedUnencr // @param inputKey // @param newLocalPassword func (client *Client) ChangeLocalPassword(inputKey InputKey, newLocalPassword SecureBytes) (*Key, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` InputKey InputKey `json:"input_key"` NewLocalPassword SecureBytes `json:"new_local_password"` }{ Type: "changeLocalPassword", + Extra: requestID, InputKey: inputKey, NewLocalPassword: newLocalPassword, }, + requestID, ) if err != nil { @@ -471,16 +535,20 @@ func (client *Client) ChangeLocalPassword(inputKey InputKey, newLocalPassword Se // @param decryptedData // @param secret func (client *Client) Encrypt(decryptedData SecureBytes, secret SecureBytes) (*Data, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` DecryptedData SecureBytes `json:"decrypted_data"` Secret SecureBytes `json:"secret"` }{ Type: "encrypt", + Extra: requestID, DecryptedData: decryptedData, Secret: secret, }, + requestID, ) if err != nil { @@ -501,16 +569,20 @@ func (client *Client) Encrypt(decryptedData SecureBytes, secret SecureBytes) (*D // @param encryptedData // @param secret func (client *Client) Decrypt(encryptedData SecureBytes, secret SecureBytes) (*Data, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` EncryptedData SecureBytes `json:"encrypted_data"` Secret SecureBytes `json:"secret"` }{ Type: "decrypt", + Extra: requestID, EncryptedData: encryptedData, Secret: secret, }, + requestID, ) if err != nil { @@ -532,18 +604,22 @@ func (client *Client) Decrypt(encryptedData SecureBytes, secret SecureBytes) (*D // @param password // @param salt func (client *Client) Kdf(iterations int32, password SecureBytes, salt SecureBytes) (*Data, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Iterations int32 `json:"iterations"` Password SecureBytes `json:"password"` Salt SecureBytes `json:"salt"` }{ Type: "kdf", + Extra: requestID, Iterations: iterations, Password: password, Salt: salt, }, + requestID, ) if err != nil { @@ -563,14 +639,18 @@ func (client *Client) Kdf(iterations int32, password SecureBytes, salt SecureByt // UnpackAccountAddress // @param accountAddress func (client *Client) UnpackAccountAddress(accountAddress string) (*UnpackedAccountAddress, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` AccountAddress string `json:"account_address"` }{ Type: "unpackAccountAddress", + Extra: requestID, AccountAddress: accountAddress, }, + requestID, ) if err != nil { @@ -590,14 +670,18 @@ func (client *Client) UnpackAccountAddress(accountAddress string) (*UnpackedAcco // PackAccountAddress // @param accountAddress func (client *Client) PackAccountAddress(accountAddress UnpackedAccountAddress) (*AccountAddress, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` AccountAddress UnpackedAccountAddress `json:"account_address"` }{ Type: "packAccountAddress", + Extra: requestID, AccountAddress: accountAddress, }, + requestID, ) if err != nil { @@ -617,14 +701,18 @@ func (client *Client) PackAccountAddress(accountAddress UnpackedAccountAddress) // GetBip39Hints // @param prefix func (client *Client) GetBip39Hints(prefix string) (*Bip39Hints, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Prefix string `json:"prefix"` }{ Type: "getBip39Hints", + Extra: requestID, Prefix: prefix, }, + requestID, ) if err != nil { @@ -644,14 +732,18 @@ func (client *Client) GetBip39Hints(prefix string) (*Bip39Hints, error) { // RawGetAccountState // @param accountAddress func (client *Client) RawGetAccountState(accountAddress AccountAddress) (*RawFullAccountState, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` AccountAddress AccountAddress `json:"account_address"` }{ Type: "raw.getAccountState", + Extra: requestID, AccountAddress: accountAddress, }, + requestID, ) if err != nil { @@ -671,20 +763,21 @@ func (client *Client) RawGetAccountState(accountAddress AccountAddress) (*RawFul // RawGetTransactions // @param accountAddress // @param fromTransactionId -// @param privateKey -func (client *Client) RawGetTransactions(accountAddress AccountAddress, fromTransactionId InternalTransactionId, privateKey InputKey) (*RawTransactions, error) { +func (client *Client) RawGetTransactions(accountAddress AccountAddress, fromTransactionId InternalTransactionId) (*RawTransactions, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` AccountAddress AccountAddress `json:"account_address"` FromTransactionId InternalTransactionId `json:"from_transaction_id"` - PrivateKey InputKey `json:"private_key"` }{ Type: "raw.getTransactions", + Extra: requestID, AccountAddress: accountAddress, FromTransactionId: fromTransactionId, - PrivateKey: privateKey, }, + requestID, ) if err != nil { @@ -704,14 +797,18 @@ func (client *Client) RawGetTransactions(accountAddress AccountAddress, fromTran // RawSendMessage // @param body func (client *Client) RawSendMessage(body []byte) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Body []byte `json:"body"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Body []byte `json:"body"` }{ - Type: "raw.sendMessage", - Body: body, + Type: "raw.sendMessage", + Extra: requestID, + Body: body, }, + requestID, ) if err != nil { @@ -733,18 +830,22 @@ func (client *Client) RawSendMessage(body []byte) (*Ok, error) { // @param destination // @param initialAccountState func (client *Client) RawCreateAndSendMessage(data []byte, destination AccountAddress, initialAccountState []byte) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Data []byte `json:"data"` Destination AccountAddress `json:"destination"` InitialAccountState []byte `json:"initial_account_state"` }{ Type: "raw.createAndSendMessage", + Extra: requestID, Data: data, Destination: destination, InitialAccountState: initialAccountState, }, + requestID, ) if err != nil { @@ -767,20 +868,24 @@ func (client *Client) RawCreateAndSendMessage(data []byte, destination AccountAd // @param initCode // @param initData func (client *Client) RawCreateQuery(body []byte, destination AccountAddress, initCode []byte, initData []byte) (*QueryInfo, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Body []byte `json:"body"` Destination AccountAddress `json:"destination"` InitCode []byte `json:"init_code"` InitData []byte `json:"init_data"` }{ Type: "raw.createQuery", + Extra: requestID, Body: body, Destination: destination, InitCode: initCode, InitData: initData, }, + requestID, ) if err != nil { @@ -801,16 +906,20 @@ func (client *Client) RawCreateQuery(body []byte, destination AccountAddress, in // @param initialAccountState // @param revision func (client *Client) GetAccountAddress(initialAccountState InitialAccountState, revision int32) (*AccountAddress, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` InitialAccountState InitialAccountState `json:"initial_account_state"` Revision int32 `json:"revision"` }{ Type: "getAccountAddress", + Extra: requestID, InitialAccountState: initialAccountState, Revision: revision, }, + requestID, ) if err != nil { @@ -830,14 +939,18 @@ func (client *Client) GetAccountAddress(initialAccountState InitialAccountState, // GuessAccountRevision // @param initialAccountState func (client *Client) GuessAccountRevision(initialAccountState InitialAccountState) (*AccountRevisionList, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` InitialAccountState InitialAccountState `json:"initial_account_state"` }{ Type: "guessAccountRevision", + Extra: requestID, InitialAccountState: initialAccountState, }, + requestID, ) if err != nil { @@ -857,14 +970,18 @@ func (client *Client) GuessAccountRevision(initialAccountState InitialAccountSta // GetAccountState // @param accountAddress func (client *Client) GetAccountState(accountAddress AccountAddress) (*FullAccountState, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` AccountAddress AccountAddress `json:"account_address"` }{ Type: "getAccountState", + Extra: requestID, AccountAddress: accountAddress, }, + requestID, ) if err != nil { @@ -887,20 +1004,24 @@ func (client *Client) GetAccountState(accountAddress AccountAddress) (*FullAccou // @param privateKey // @param timeout func (client *Client) CreateQuery(action Action, address AccountAddress, privateKey InputKey, timeout int32) (*QueryInfo, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Action Action `json:"action"` Address AccountAddress `json:"address"` PrivateKey InputKey `json:"private_key"` Timeout int32 `json:"timeout"` }{ Type: "createQuery", + Extra: requestID, Action: action, Address: address, PrivateKey: privateKey, Timeout: timeout, }, + requestID, ) if err != nil { @@ -921,16 +1042,20 @@ func (client *Client) CreateQuery(action Action, address AccountAddress, private // @param data // @param inputKey func (client *Client) MsgDecrypt(data MsgDataEncryptedArray, inputKey InputKey) (*MsgDataDecryptedArray, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Data MsgDataEncryptedArray `json:"data"` InputKey InputKey `json:"input_key"` }{ Type: "msg.decrypt", + Extra: requestID, Data: data, InputKey: inputKey, }, + requestID, ) if err != nil { @@ -951,16 +1076,20 @@ func (client *Client) MsgDecrypt(data MsgDataEncryptedArray, inputKey InputKey) // @param data // @param proof func (client *Client) MsgDecryptWithProof(data MsgDataEncrypted, proof []byte) (*MsgData, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Data MsgDataEncrypted `json:"data"` Proof []byte `json:"proof"` }{ Type: "msg.decryptWithProof", + Extra: requestID, Data: data, Proof: proof, }, + requestID, ) if err != nil { @@ -980,14 +1109,18 @@ func (client *Client) MsgDecryptWithProof(data MsgDataEncrypted, proof []byte) ( // QuerySend // @param id func (client *Client) QuerySend(id int64) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Id int64 `json:"id"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Id int64 `json:"id"` }{ - Type: "query.send", - Id: id, + Type: "query.send", + Extra: requestID, + Id: id, }, + requestID, ) if err != nil { @@ -1007,14 +1140,18 @@ func (client *Client) QuerySend(id int64) (*Ok, error) { // QueryForget // @param id func (client *Client) QueryForget(id int64) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Id int64 `json:"id"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Id int64 `json:"id"` }{ - Type: "query.forget", - Id: id, + Type: "query.forget", + Extra: requestID, + Id: id, }, + requestID, ) if err != nil { @@ -1034,14 +1171,18 @@ func (client *Client) QueryForget(id int64) (*Ok, error) { // QueryGetInfo // @param id func (client *Client) QueryGetInfo(id int64) (*QueryInfo, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Id int64 `json:"id"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Id int64 `json:"id"` }{ - Type: "query.getInfo", - Id: id, + Type: "query.getInfo", + Extra: requestID, + Id: id, }, + requestID, ) if err != nil { @@ -1061,14 +1202,18 @@ func (client *Client) QueryGetInfo(id int64) (*QueryInfo, error) { // SmcLoad // @param accountAddress func (client *Client) SmcLoad(accountAddress AccountAddress) (*SmcInfo, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` AccountAddress AccountAddress `json:"account_address"` }{ Type: "smc.load", + Extra: requestID, AccountAddress: accountAddress, }, + requestID, ) if err != nil { @@ -1088,14 +1233,18 @@ func (client *Client) SmcLoad(accountAddress AccountAddress) (*SmcInfo, error) { // SmcGetCode // @param id func (client *Client) SmcGetCode(id int64) (*TvmCell, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Id int64 `json:"id"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Id int64 `json:"id"` }{ - Type: "smc.getCode", - Id: id, + Type: "smc.getCode", + Extra: requestID, + Id: id, }, + requestID, ) if err != nil { @@ -1115,14 +1264,18 @@ func (client *Client) SmcGetCode(id int64) (*TvmCell, error) { // SmcGetData // @param id func (client *Client) SmcGetData(id int64) (*TvmCell, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Id int64 `json:"id"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Id int64 `json:"id"` }{ - Type: "smc.getData", - Id: id, + Type: "smc.getData", + Extra: requestID, + Id: id, }, + requestID, ) if err != nil { @@ -1142,14 +1295,18 @@ func (client *Client) SmcGetData(id int64) (*TvmCell, error) { // SmcGetState // @param id func (client *Client) SmcGetState(id int64) (*TvmCell, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Id int64 `json:"id"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Id int64 `json:"id"` }{ - Type: "smc.getState", - Id: id, + Type: "smc.getState", + Extra: requestID, + Id: id, }, + requestID, ) if err != nil { @@ -1171,18 +1328,22 @@ func (client *Client) SmcGetState(id int64) (*TvmCell, error) { // @param method // @param stack func (client *Client) SmcRunGetMethod(id int64, method SmcMethodId, stack []TvmStackEntry) (*SmcRunResult, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Id int64 `json:"id"` Method SmcMethodId `json:"method"` Stack []TvmStackEntry `json:"stack"` }{ Type: "smc.runGetMethod", + Extra: requestID, Id: id, Method: method, Stack: stack, }, + requestID, ) if err != nil { @@ -1205,20 +1366,24 @@ func (client *Client) SmcRunGetMethod(id int64, method SmcMethodId, stack []TvmS // @param name // @param ttl func (client *Client) DnsResolve(accountAddress AccountAddress, category int32, name string, ttl int32) (*DnsResolved, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` AccountAddress AccountAddress `json:"account_address"` Category int32 `json:"category"` Name string `json:"name"` Ttl int32 `json:"ttl"` }{ Type: "dns.resolve", + Extra: requestID, AccountAddress: accountAddress, Category: category, Name: name, Ttl: ttl, }, + requestID, ) if err != nil { @@ -1239,16 +1404,20 @@ func (client *Client) DnsResolve(accountAddress AccountAddress, category int32, // @param bytes // @param id func (client *Client) OnLiteServerQueryResult(bytes []byte, id JSONInt64) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Bytes []byte `json:"bytes"` Id JSONInt64 `json:"id"` }{ Type: "onLiteServerQueryResult", + Extra: requestID, Bytes: bytes, Id: id, }, + requestID, ) if err != nil { @@ -1269,16 +1438,20 @@ func (client *Client) OnLiteServerQueryResult(bytes []byte, id JSONInt64) (*Ok, // @param error // @param id func (client *Client) OnLiteServerQueryError(error Error, id JSONInt64) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Error Error `json:"error"` Id JSONInt64 `json:"id"` }{ Type: "onLiteServerQueryError", + Extra: requestID, Error: error, Id: id, }, + requestID, ) if err != nil { @@ -1299,16 +1472,20 @@ func (client *Client) OnLiteServerQueryError(error Error, id JSONInt64) (*Ok, er // @param function // @param id func (client *Client) WithBlock(function Function, id TonBlockIdExt) (*Object, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Function Function `json:"function"` Id TonBlockIdExt `json:"id"` }{ Type: "withBlock", + Extra: requestID, Function: function, Id: id, }, + requestID, ) if err != nil { @@ -1328,14 +1505,18 @@ func (client *Client) WithBlock(function Function, id TonBlockIdExt) (*Object, e // RunTests // @param dir func (client *Client) RunTests(dir string) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Dir string `json:"dir"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Dir string `json:"dir"` }{ - Type: "runTests", - Dir: dir, + Type: "runTests", + Extra: requestID, + Dir: dir, }, + requestID, ) if err != nil { @@ -1354,12 +1535,16 @@ func (client *Client) RunTests(dir string) (*Ok, error) { // LiteServerGetInfo func (client *Client) LiteServerGetInfo() (*LiteServerInfo, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` + Type string `json:"@type"` + Extra string `json:"@extra"` }{ - Type: "liteServer.getInfo", + Type: "liteServer.getInfo", + Extra: requestID, }, + requestID, ) if err != nil { @@ -1379,14 +1564,18 @@ func (client *Client) LiteServerGetInfo() (*LiteServerInfo, error) { // SetLogStream Sets new log stream for internal logging of tonlib. This is an offline method. Can be called before authorization. Can be called synchronously // @param logStream New log stream func (client *Client) SetLogStream(logStream LogStream) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` LogStream LogStream `json:"log_stream"` }{ Type: "setLogStream", + Extra: requestID, LogStream: logStream, }, + requestID, ) if err != nil { @@ -1405,12 +1594,16 @@ func (client *Client) SetLogStream(logStream LogStream) (*Ok, error) { // GetLogStream Returns information about currently used log stream for internal logging of tonlib. This is an offline method. Can be called before authorization. Can be called synchronously func (client *Client) GetLogStream() (LogStream, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` + Type string `json:"@type"` + Extra string `json:"@extra"` }{ - Type: "getLogStream", + Type: "getLogStream", + Extra: requestID, }, + requestID, ) if err != nil { @@ -1446,14 +1639,18 @@ func (client *Client) GetLogStream() (LogStream, error) { // SetLogVerbosityLevel Sets the verbosity level of the internal logging of tonlib. This is an offline method. Can be called before authorization. Can be called synchronously // @param newVerbosityLevel New value of the verbosity level for logging. Value 0 corresponds to fatal errors, value 1 corresponds to errors, value 2 corresponds to warnings and debug warnings, value 3 corresponds to informational, value 4 corresponds to debug, value 5 corresponds to verbose debug, value greater than 5 and up to 1023 can be used to enable even more logging func (client *Client) SetLogVerbosityLevel(newVerbosityLevel int32) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` NewVerbosityLevel int32 `json:"new_verbosity_level"` }{ Type: "setLogVerbosityLevel", + Extra: requestID, NewVerbosityLevel: newVerbosityLevel, }, + requestID, ) if err != nil { @@ -1472,12 +1669,16 @@ func (client *Client) SetLogVerbosityLevel(newVerbosityLevel int32) (*Ok, error) // GetLogVerbosityLevel Returns current verbosity level of the internal logging of tonlib. This is an offline method. Can be called before authorization. Can be called synchronously func (client *Client) GetLogVerbosityLevel() (*LogVerbosityLevel, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` + Type string `json:"@type"` + Extra string `json:"@extra"` }{ - Type: "getLogVerbosityLevel", + Type: "getLogVerbosityLevel", + Extra: requestID, }, + requestID, ) if err != nil { @@ -1496,12 +1697,16 @@ func (client *Client) GetLogVerbosityLevel() (*LogVerbosityLevel, error) { // GetLogTags Returns list of available tonlib internal log tags, for example, ["actor", "binlog", "connections", "notifications", "proxy"]. This is an offline method. Can be called before authorization. Can be called synchronously func (client *Client) GetLogTags() (*LogTags, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` + Type string `json:"@type"` + Extra string `json:"@extra"` }{ - Type: "getLogTags", + Type: "getLogTags", + Extra: requestID, }, + requestID, ) if err != nil { @@ -1522,16 +1727,20 @@ func (client *Client) GetLogTags() (*LogTags, error) { // @param newVerbosityLevel New verbosity level; 1-1024 // @param tag Logging tag to change verbosity level func (client *Client) SetLogTagVerbosityLevel(newVerbosityLevel int32, tag string) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` NewVerbosityLevel int32 `json:"new_verbosity_level"` Tag string `json:"tag"` }{ Type: "setLogTagVerbosityLevel", + Extra: requestID, NewVerbosityLevel: newVerbosityLevel, Tag: tag, }, + requestID, ) if err != nil { @@ -1551,14 +1760,18 @@ func (client *Client) SetLogTagVerbosityLevel(newVerbosityLevel int32, tag strin // GetLogTagVerbosityLevel Returns current verbosity level for a specified tonlib internal log tag. This is an offline method. Can be called before authorization. Can be called synchronously // @param tag Logging tag to change verbosity level func (client *Client) GetLogTagVerbosityLevel(tag string) (*LogVerbosityLevel, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { - Type string `json:"@type"` - Tag string `json:"tag"` + Type string `json:"@type"` + Extra string `json:"@extra"` + Tag string `json:"tag"` }{ - Type: "getLogTagVerbosityLevel", - Tag: tag, + Type: "getLogTagVerbosityLevel", + Extra: requestID, + Tag: tag, }, + requestID, ) if err != nil { @@ -1579,16 +1792,20 @@ func (client *Client) GetLogTagVerbosityLevel(tag string) (*LogVerbosityLevel, e // @param text Text of a message to log // @param verbosityLevel Minimum verbosity level needed for the message to be logged, 0-1023 func (client *Client) AddLogMessage(text string, verbosityLevel int32) (*Ok, error) { + requestID := client.GenerateRequestID() result, err := client.executeAsynchronously( struct { Type string `json:"@type"` + Extra string `json:"@extra"` Text string `json:"text"` VerbosityLevel int32 `json:"verbosity_level"` }{ Type: "addLogMessage", + Extra: requestID, Text: text, VerbosityLevel: verbosityLevel, }, + requestID, ) if err != nil { diff --git a/v2/simple.go b/v2/simple.go index 76ad921..6d570e2 100644 --- a/v2/simple.go +++ b/v2/simple.go @@ -374,8 +374,8 @@ func (client *Client) GetAccountStateSimple(address string) (*FullAccountState, return client.GetAccountState(*accountAddress) } -func (client *Client) GetLastBlock() (string, error) { - return client.Sync(SyncState(SyncState{})) +func (client *Client) GetLastBlock() (*TONResult, error) { + return client.Sync(SyncState(SyncState{}), nil) } func (client *Client) TonlibSendFile(bocFilePath string) error { diff --git a/v2/structs.go b/v2/structs.go index e3cd511..bbee88a 100755 --- a/v2/structs.go +++ b/v2/structs.go @@ -665,7 +665,7 @@ func NewAccountRevisionList(revisions []int32) *AccountRevisionList { // UnpackedAccountAddress type UnpackedAccountAddress struct { tonCommon - Addr string `json:"addr"` // + Addr []byte `json:"addr"` // Bounceable bool `json:"bounceable"` // Testnet bool `json:"testnet"` // WorkchainId int32 `json:"workchain_id"` // @@ -682,7 +682,7 @@ func (unpackedAccountAddress *UnpackedAccountAddress) MessageType() string { // @param bounceable // @param testnet // @param workchainId -func NewUnpackedAccountAddress(addr string, bounceable bool, testnet bool, workchainId int32) *UnpackedAccountAddress { +func NewUnpackedAccountAddress(addr []byte, bounceable bool, testnet bool, workchainId int32) *UnpackedAccountAddress { unpackedAccountAddressTemp := UnpackedAccountAddress{ tonCommon: tonCommon{Type: "unpackedAccountAddress"}, Addr: addr, @@ -697,7 +697,7 @@ func NewUnpackedAccountAddress(addr string, bounceable bool, testnet bool, workc // InternalTransactionId type InternalTransactionId struct { tonCommon - Hash string `json:"hash"` // + Hash []byte `json:"hash"` // Lt JSONInt64 `json:"lt"` // } @@ -710,7 +710,7 @@ func (internalTransactionId *InternalTransactionId) MessageType() string { // // @param hash // @param lt -func NewInternalTransactionId(hash string, lt JSONInt64) *InternalTransactionId { +func NewInternalTransactionId(hash []byte, lt JSONInt64) *InternalTransactionId { internalTransactionIdTemp := InternalTransactionId{ tonCommon: tonCommon{Type: "internal.transactionId"}, Hash: hash, @@ -752,8 +752,8 @@ func NewTonBlockId(seqno int32, shard JSONInt64, workchain int32) *TonBlockId { // TonBlockIdExt type TonBlockIdExt struct { tonCommon - FileHash string `json:"file_hash"` // - RootHash string `json:"root_hash"` // + FileHash []byte `json:"file_hash"` // + RootHash []byte `json:"root_hash"` // Seqno int32 `json:"seqno"` // Shard JSONInt64 `json:"shard"` // Workchain int32 `json:"workchain"` // @@ -771,7 +771,7 @@ func (tonBlockIdExt *TonBlockIdExt) MessageType() string { // @param seqno // @param shard // @param workchain -func NewTonBlockIdExt(fileHash string, rootHash string, seqno int32, shard JSONInt64, workchain int32) *TonBlockIdExt { +func NewTonBlockIdExt(fileHash []byte, rootHash []byte, seqno int32, shard JSONInt64, workchain int32) *TonBlockIdExt { tonBlockIdExtTemp := TonBlockIdExt{ tonCommon: tonCommon{Type: "ton.blockIdExt"}, FileHash: fileHash, @@ -791,7 +791,7 @@ type RawFullAccountState struct { BlockId *TonBlockIdExt `json:"block_id"` // Code string `json:"code"` // Data string `json:"data"` // - FrozenHash string `json:"frozen_hash"` // + FrozenHash []byte `json:"frozen_hash"` // LastTransactionId *InternalTransactionId `json:"last_transaction_id"` // SyncUtime int64 `json:"sync_utime"` // } @@ -810,7 +810,7 @@ func (rawFullAccountState *RawFullAccountState) MessageType() string { // @param frozenHash // @param lastTransactionId // @param syncUtime -func NewRawFullAccountState(balance JSONInt64, blockId *TonBlockIdExt, code string, data string, frozenHash string, lastTransactionId *InternalTransactionId, syncUtime int64) *RawFullAccountState { +func NewRawFullAccountState(balance JSONInt64, blockId *TonBlockIdExt, code string, data string, frozenHash []byte, lastTransactionId *InternalTransactionId, syncUtime int64) *RawFullAccountState { rawFullAccountStateTemp := RawFullAccountState{ tonCommon: tonCommon{Type: "raw.fullAccountState"}, Balance: balance, @@ -828,14 +828,14 @@ func NewRawFullAccountState(balance JSONInt64, blockId *TonBlockIdExt, code stri // RawMessage type RawMessage struct { tonCommon - BodyHash string `json:"body_hash"` // + BodyHash []byte `json:"body_hash"` // CreatedLt JSONInt64 `json:"created_lt"` // Destination *AccountAddress `json:"destination"` // FwdFee JSONInt64 `json:"fwd_fee"` // IhrFee JSONInt64 `json:"ihr_fee"` // - MsgData MsgData `json:"msg_data"` // Source *AccountAddress `json:"source"` // Value JSONInt64 `json:"value"` // + MsgData *MsgDataText `json:"msg_data"` // } // MessageType return the string telegram-type of RawMessage @@ -850,10 +850,11 @@ func (rawMessage *RawMessage) MessageType() string { // @param destination // @param fwdFee // @param ihrFee -// @param msgData +// @param isMessageEncrypted +// @param message // @param source // @param value -func NewRawMessage(bodyHash string, createdLt JSONInt64, destination *AccountAddress, fwdFee JSONInt64, ihrFee JSONInt64, msgData MsgData, source *AccountAddress, value JSONInt64) *RawMessage { +func NewRawMessage(bodyHash []byte, createdLt JSONInt64, destination *AccountAddress, fwdFee JSONInt64, ihrFee JSONInt64, msgData *MsgDataText, source *AccountAddress, value JSONInt64) *RawMessage { rawMessageTemp := RawMessage{ tonCommon: tonCommon{Type: "raw.message"}, BodyHash: bodyHash, @@ -1140,7 +1141,7 @@ type RawAccountState struct { tonCommon Code string `json:"code"` // Data string `json:"data"` // - FrozenHash string `json:"frozen_hash"` // + FrozenHash []byte `json:"frozen_hash"` // } // MessageType return the string telegram-type of RawAccountState @@ -1153,7 +1154,7 @@ func (rawAccountState *RawAccountState) MessageType() string { // @param code // @param data // @param frozenHash -func NewRawAccountState(code string, data string, frozenHash string) *RawAccountState { +func NewRawAccountState(code string, data string, frozenHash []byte) *RawAccountState { rawAccountStateTemp := RawAccountState{ tonCommon: tonCommon{Type: "raw.accountState"}, Code: code, @@ -1334,7 +1335,7 @@ func NewDnsAccountState(walletId JSONInt64) *DnsAccountState { // UninitedAccountState type UninitedAccountState struct { tonCommon - FrozenHash string `json:"frozen_hash"` // + FrozenHash []byte `json:"frozen_hash"` // } // MessageType return the string telegram-type of UninitedAccountState @@ -1345,7 +1346,7 @@ func (uninitedAccountState *UninitedAccountState) MessageType() string { // NewUninitedAccountState creates a new UninitedAccountState // // @param frozenHash -func NewUninitedAccountState(frozenHash string) *UninitedAccountState { +func NewUninitedAccountState(frozenHash []byte) *UninitedAccountState { uninitedAccountStateTemp := UninitedAccountState{ tonCommon: tonCommon{Type: "uninited.accountState"}, FrozenHash: frozenHash, @@ -1464,7 +1465,7 @@ func NewMsgDataRaw(body string) *MsgDataRaw { // MsgDataText type MsgDataText struct { tonCommon - Text string `json:"text"` // + Text []byte `json:"text"` // } // MessageType return the string telegram-type of MsgDataText @@ -1475,7 +1476,7 @@ func (msgDataText *MsgDataText) MessageType() string { // NewMsgDataText creates a new MsgDataText // // @param text -func NewMsgDataText(text string) *MsgDataText { +func NewMsgDataText(text []byte) *MsgDataText { msgDataTextTemp := MsgDataText{ tonCommon: tonCommon{Type: "msg.dataText"}, Text: text, @@ -1632,7 +1633,7 @@ func NewMsgDataDecryptedArray(elements []MsgDataDecrypted) *MsgDataDecryptedArra type MsgMessage struct { tonCommon Amount JSONInt64 `json:"amount"` // - Data MsgData `json:"data"` // + Data MsgData `json:"data"` // Destination *AccountAddress `json:"destination"` // PublicKey string `json:"public_key"` // } @@ -2026,7 +2027,7 @@ func NewQueryFees(destinationFees []Fees, sourceFees *Fees) *QueryFees { // QueryInfo type QueryInfo struct { tonCommon - BodyHash string `json:"body_hash"` // + BodyHash []byte `json:"body_hash"` // Id int64 `json:"id"` // ValidUntil int64 `json:"valid_until"` // } @@ -2041,7 +2042,7 @@ func (queryInfo *QueryInfo) MessageType() string { // @param bodyHash // @param id // @param validUntil -func NewQueryInfo(bodyHash string, id int64, validUntil int64) *QueryInfo { +func NewQueryInfo(bodyHash []byte, id int64, validUntil int64) *QueryInfo { queryInfoTemp := QueryInfo{ tonCommon: tonCommon{Type: "query.info"}, BodyHash: bodyHash, diff --git a/v2/utils.go b/v2/utils.go index 75cf58d..5e6102f 100644 --- a/v2/utils.go +++ b/v2/utils.go @@ -1,6 +1,7 @@ package v2 import ( + "math/rand" "encoding/json" "io/ioutil" "math/big" @@ -90,3 +91,13 @@ func fileExists(filename string) bool { } return !info.IsDir() } + +var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + +func RandSeq(n int) string { + b := make([]rune, n) + for i := range b { + b[i] = letters[rand.Intn(len(letters))] + } + return string(b) +}