diff --git a/Lib9c b/Lib9c index 76107269e..9029a8c11 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 76107269edb4b48b84f0bf06700465457d17e2a4 +Subproject commit 9029a8c11b916689de3b6a7cdb440a2862580216 diff --git a/NineChronicles.Headless.Executable/Commands/TxCommand.cs b/NineChronicles.Headless.Executable/Commands/TxCommand.cs index 823073764..6c6ddaf94 100644 --- a/NineChronicles.Headless.Executable/Commands/TxCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/TxCommand.cs @@ -190,34 +190,6 @@ public void MigrationActivatedAccountsState() _console.Out.WriteLine(ByteUtil.Hex(raw)); } - [Command(Description = "Create MigrationAvatarState action and dump it.")] - public void MigrationAvatarState( - [Argument("directory-path", Description = "path of the directory contained hex-encoded avatar states.")] - string directoryPath, - [Argument("output-path", Description = "path of the output file dumped action.")] - string outputPath - ) - { - var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories); - var avatarStates = files.Select(a => - { - var raw = File.ReadAllText(a); - return (Dictionary)_codec.Decode(ByteUtil.ParseHex(raw)); - }).ToList(); - var action = new MigrationAvatarState() - { - avatarStates = avatarStates - }; - - var encoded = new List( - (Text)nameof(Nekoyume.Action.MigrationAvatarState), - action.PlainValue - ); - - byte[] raw = _codec.Encode(encoded); - File.WriteAllText(outputPath, ByteUtil.Hex(raw)); - } - [Command(Description = "Create AddRedeemCode action and dump it.")] public void AddRedeemCode( [Argument("TABLE-PATH", Description = "A table file path for RedeemCodeListSheet")] diff --git a/NineChronicles.Headless/BlockChainService.cs b/NineChronicles.Headless/BlockChainService.cs index 18989f137..db7e565ad 100644 --- a/NineChronicles.Headless/BlockChainService.cs +++ b/NineChronicles.Headless/BlockChainService.cs @@ -199,7 +199,7 @@ public async UnaryResult> GetAvatarStatesByBlockHash( var addresses = addressBytesList.Select(a => new Address(a)).ToList(); var taskList = addresses.Select(address => Task.Run(() => { - var value = worldState.GetFullAvatarStateRaw(address); + var value = GetFullAvatarStateRaw(worldState, address); result.TryAdd(address.ToByteArray(), _codec.Encode(value ?? Null.Value)); })); @@ -217,7 +217,7 @@ public async UnaryResult> GetAvatarStatesByStateRootH var result = new ConcurrentDictionary(); var taskList = addresses.Select(address => Task.Run(() => { - var value = worldState.GetFullAvatarStateRaw(address); + var value = GetFullAvatarStateRaw(worldState, address); result.TryAdd(address.ToByteArray(), _codec.Encode(value ?? Null.Value)); })); @@ -447,5 +447,33 @@ public UnaryResult RemoveClient(byte[] addressBytes) _publisher.RemoveClient(address).Wait(); return new UnaryResult(true); } + + // Returning value is a list of [ Avatar, Inventory, QuestList, WorldInformation ] + private static IValue GetFullAvatarStateRaw(IWorldState worldState, Address address) + { + var serializedAvatarRaw = worldState.GetAccountState(Addresses.Avatar).GetState(address); + if (serializedAvatarRaw is not List) + { + Log.Warning( + "Avatar state ({AvatarAddress}) should be " + + "List but: {Raw}", + address.ToHex(), + serializedAvatarRaw); + return null; + } + + var serializedInventoryRaw = + worldState.GetAccountState(Addresses.Inventory).GetState(address); + var serializedQuestListRaw = + worldState.GetAccountState(Addresses.QuestList).GetState(address); + var serializedWorldInformationRaw = + worldState.GetAccountState(Addresses.WorldInformation).GetState(address); + + return new List( + serializedAvatarRaw, + serializedInventoryRaw!, + serializedQuestListRaw!, + serializedWorldInformationRaw!); + } } }