Skip to content

Commit

Permalink
chore: apply suggestions from the code review
Browse files Browse the repository at this point in the history
  • Loading branch information
limebell committed Dec 31, 2024
1 parent 557e951 commit a56650d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 38 deletions.
18 changes: 5 additions & 13 deletions sdk/node/Libplanet.Node.Tests/Services/BlockChainServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,11 @@ public void Create_Using_Genesis_Configuration_Test()
var serviceProvider = services.BuildServiceProvider();
var blockChainService = serviceProvider.GetRequiredService<IBlockChainService>();
var blockChain = blockChainService.BlockChain;

Assert.Equal(
(Text)"A",
blockChain.GetNextWorldState()?.GetAccountState(accountA).GetState(addressA));
Assert.Equal(
(Integer)123,
blockChain.GetNextWorldState()?.GetAccountState(accountA).GetState(addressB));
Assert.Equal(
(Text)"B",
blockChain.GetNextWorldState()?.GetAccountState(accountB).GetState(addressA));
Assert.Equal(
(Integer)456,
blockChain.GetNextWorldState()?.GetAccountState(accountB).GetState(addressB));
var worldState = blockChain.GetNextWorldState()!;
Assert.Equal((Text)"A", worldState.GetAccountState(accountA).GetState(addressA));
Assert.Equal((Integer)123, worldState.GetAccountState(accountA).GetState(addressB));
Assert.Equal((Text)"B", worldState.GetAccountState(accountB).GetState(addressA));
Assert.Equal((Integer)456, worldState.GetAccountState(accountB).GetState(addressB));
}
finally
{
Expand Down
34 changes: 9 additions & 25 deletions sdk/node/Libplanet.Node/Services/BlockChainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private static Block CreateGenesisBlockFromConfiguration(
byte[] config,
IStateStore stateStore)
{
Dictionary<string, Dictionary<string, string>>? data =
Dictionary<string, Dictionary<string, string>>? data =
JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(config);
if (data == null || data.Count == 0)
{
Expand All @@ -209,33 +209,17 @@ private static Block CreateGenesisBlockFromConfiguration(

foreach (var accountKv in data)
{
try
{
var key = new Address(accountKv.Key);
IAccount account = world.GetAccount(key);

foreach (var stateKv in accountKv.Value)
{
try
{
account = account.SetState(
new Address(stateKv.Key),
codec.Decode(ByteUtil.ParseHex(stateKv.Value)));
}
catch (Exception e)
{
// skip state
Console.WriteLine(e);
}
}
var key = new Address(accountKv.Key);
IAccount account = world.GetAccount(key);

world = world.SetAccount(key, account);
}
catch (Exception e)
foreach (var stateKv in accountKv.Value)
{
// skip account
Console.WriteLine(e);
account = account.SetState(
new Address(stateKv.Key),
codec.Decode(ByteUtil.ParseHex(stateKv.Value)));
}

world = world.SetAccount(key, account);
}

var worldTrie = world.Trie;
Expand Down

0 comments on commit a56650d

Please sign in to comment.