justdmitry / TonLib.NET

tonlibjson wrapper for .NET
MIT License
10 stars 6 forks source link

Extensibility, liteServer.* methods. #7

Open jamescarter-le opened 2 days ago

jamescarter-le commented 2 days ago

Hello again! Wonderful lib as always.

I'm looking to add through extensibility or as a PR, the ability to use more liteServer.* methods available here: https://raw.githubusercontent.com/ton-blockchain/ton/master/tl/generate/scheme/lite_api.tl

Specifically I want the capability to call liteServer.runSmcMethod which allows you to specify the block height you are executing at, and so read historical state.

I've seen other libs implement this such as this JS example: https://github.com/ton-core/ton-lite-client/blob/8e7089c35aaac7b7b75833c3b68a777d1d023c84/src/client.ts#L408

I first tried to add liteServer.getVersion which is on the referenced .tl and seems innocous enough, should just give a subset of what is available in liteServer.getInfo.

I've added this Request:

[TLSchema("liteServer.getVersion = liteServer.Version")]
public class GetVersion : RequestBase<Types.LiteServer.VersionDto>
{
    // Nothing
}

But I get TonLibDotNet.TonClientException: 'Empty response received'

Am I misunderstanding how to add new request to your SDK? I'm not yet using extensibility, I've just added it to TonClientLiteServerExtensions and referencing it in Samples just to check it works.

Any advice would be appreciated.

justdmitry commented 2 days ago

Hi, Thanks for warm words,

As soon as your new request had been sent by library - I guess you made it correctly (but of course providing link to your forked repo and commit would help more), and it doesn't work due to other reason: you can't add method(s) from that TL file :(

TonLib.Net uses intermediate libtonjson library for communicating with liteserver, which has it's own methods list (https://github.com/ton-blockchain/ton/blob/master/tl/generate/scheme/tonlib_api.tl) and translates them to liteserver's ones and back. Direct communication with liteserver (without libtonjson, by lite_api.tl) requires different (binary) protocol which is out of scope of TonLib.Net.

For your particular task (running get-method on previous contract states) you may try using SmcLoadByTransaction (instead SmcLoad) to provide desired transactionId, and then run get methods using it.