Skip to content

Commit 470e2fb

Browse files
committed
+ GetAccountAddress
1 parent fd56f82 commit 470e2fb

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using TonLibDotNet.Types.Wallet;
2+
3+
namespace TonLibDotNet.Requests
4+
{
5+
public class GetAccountAddressTests
6+
{
7+
[Fact]
8+
public void DeserializeOk()
9+
{
10+
var baseObj = new TonJsonSerializer().Deserialize(SampleValues.GetAccountAddress);
11+
12+
Assert.NotNull(baseObj);
13+
14+
var obj = Assert.IsType<GetAccountAddress>(baseObj);
15+
16+
var ias = Assert.IsType<V3InitialAccountState>(obj.InitialAccountState);
17+
Assert.Equal("PuZ....mpU9", ias.PublicKey);
18+
Assert.Equal(698983191, ias.WalletId);
19+
20+
Assert.Equal(3, obj.Revision);
21+
Assert.Equal(-1, obj.WorkchainId);
22+
}
23+
}
24+
}

TonLibDotNet.Tests/SampleValues.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TonLibDotNet.Tests/SampleValues.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@
193193
<data name="FullAccountState" xml:space="preserve">
194194
<value>{"@type":"fullAccountState","address":{"@type":"accountAddress","account_address":"EQCJTkhd1W2wztkVNp_dsKBpv2SIoUWoIyzI7mQrbSrj_NSh"},"balance":"136217239329079","last_transaction_id":{"@type":"internal.transactionId","lt":"34942442000005","hash":"vhl79O/OZ4LCC7cdkKj22uNv5diIrIltOLujpFOLwTk="},"block_id":{"@type":"ton.blockIdExt","workchain":-1,"shard":"-9223372036854775808","seqno":27011756,"root_hash":"AhS55h8lmOyxtw29gWux0XZzXgiAbE69UsP44xIWdXM=","file_hash":"TwDj86Fbvgvxte2UXpYtm2CpMSC/wIyxZph6mPDn99A="},"sync_utime":1675249913,"account_state":{"@type":"wallet.v3.accountState","wallet_id":"698983191","seqno":35},"revision":2}</value>
195195
</data>
196+
<data name="GetAccountAddress" xml:space="preserve">
197+
<value>{"@type":"getAccountAddress","initial_account_state":{"@type":"wallet.v3.initialAccountState","public_key":"PuZ....mpU9","wallet_id":698983191},"revision":3,"workchain_id":-1}</value>
198+
</data>
196199
<data name="GetAccountState" xml:space="preserve">
197200
<value>{"@type":"getAccountState","account_address":{"@type":"accountAddress","account_address":"EQCJTkhd1W2wztkVNp_dsKBpv2SIoUWoIyzI7mQrbSrj_NSh"}}</value>
198201
</data>

TonLibDotNet/Extensions/TonClientExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ namespace TonLibDotNet
55
{
66
public static class TonClientExtensions
77
{
8+
/// <summary>
9+
/// Calculate the address of a new wallet smart contract.
10+
/// </summary>
11+
/// <param name="client">ITonClient instance.</param>
12+
/// <param name="initialAccountState">Desired wallet type: <see cref="Types.Wallet.V3InitialAccountState"/> or <see cref="Types.Wallet.HighloadV1InitialAccountState"/> or <see cref="Types.Wallet.HighloadV2InitialAccountState"/>.</param>
13+
/// <param name="revision">Use <b>0</b> for default (latest) revision, positive value for specific revision, or <b>-1</b> for experimental (newest) revision (only for debug purpose).</param>
14+
/// <param name="workchainId">Use <b>-1</b> for masterchain, <b>0</b> for basechain.</param>
15+
/// <remarks>Executes as static (without LiteServer call).</remarks>
16+
/// <seealso href="https://ton.org/docs/develop/dapps/asset-processing/#deploying-wallet"/>
17+
/// <seealso href="https://github.com/ton-blockchain/ton/blob/v2023.01/tonlib/tonlib/TonlibClient.cpp#L2869" />
18+
public static Task<AccountAddress> GetAccountAddress(this ITonClient client, InitialAccountState initialAccountState, int revision = 0, int workchainId = 0)
19+
{
20+
ArgumentNullException.ThrowIfNull(initialAccountState);
21+
22+
return client.Execute(new GetAccountAddress(initialAccountState) { Revision = revision, WorkchainId = workchainId });
23+
}
24+
825
/// <summary>
926
/// Returns <see cref="FullAccountState"/> for specified account address.
1027
/// </summary>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using TonLibDotNet.Types;
2+
3+
namespace TonLibDotNet.Requests
4+
{
5+
[TLSchema("getAccountAddress initial_account_state:InitialAccountState revision:int32 workchain_id:int32 = AccountAddress")]
6+
public class GetAccountAddress : RequestBase<AccountAddress>
7+
{
8+
public GetAccountAddress(InitialAccountState initialAccountState)
9+
{
10+
// Proof: https://github.com/ton-blockchain/ton/blob/v2023.01/tonlib/tonlib/TonlibClient.cpp#L1962
11+
IsStatic = true;
12+
13+
InitialAccountState = initialAccountState ?? throw new ArgumentNullException(nameof(initialAccountState));
14+
}
15+
16+
public InitialAccountState InitialAccountState { get; set; }
17+
18+
public int Revision { get; set; }
19+
20+
public int WorkchainId { get; set; }
21+
}
22+
}

0 commit comments

Comments
 (0)