From 92085981bb31ef5b2160a4557cbd0607b0b52a6a Mon Sep 17 00:00:00 2001 From: ilgyu Date: Fri, 27 Oct 2023 15:28:14 +0900 Subject: [PATCH] bump: NineChronicles.RPC.Shared --- NineChronicles.Headless/BlockChainService.cs | 43 ++++++++++++++------ NineChronicles.RPC.Shared | 2 +- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/NineChronicles.Headless/BlockChainService.cs b/NineChronicles.Headless/BlockChainService.cs index ec1619c52..a94b95ec6 100644 --- a/NineChronicles.Headless/BlockChainService.cs +++ b/NineChronicles.Headless/BlockChainService.cs @@ -5,7 +5,6 @@ using System.Collections.Immutable; using System.Linq; using System.Security.Cryptography; -using System.Threading.Tasks; using Bencodex; using Bencodex.Types; using Libplanet.Blockchain; @@ -19,7 +18,6 @@ using MagicOnion; using MagicOnion.Server; using Nekoyume; -using Nekoyume.Helper; using Nekoyume.Model.State; using Nekoyume.Module; using Nekoyume.Shared.Services; @@ -127,9 +125,9 @@ public UnaryResult GetState(byte[] addressBytes, byte[] accountBytes, by return new UnaryResult(encoded); } - public UnaryResult GetStateBySrh(byte[] addressBytes, byte[] stateRootHashBytes) + public UnaryResult GetState(byte[] addressBytes, byte[] accountStateRootHashBytes) { - var stateRootHash = new HashDigest(stateRootHashBytes); + var stateRootHash = new HashDigest(accountStateRootHashBytes); var address = new Address(addressBytes); IValue state = _blockChain.GetAccountState(stateRootHash).GetState(address); byte[] encoded = _codec.Encode(state ?? Null.Value); @@ -148,11 +146,11 @@ public UnaryResult> GetAvatarStates( return new UnaryResult>(result); } - public UnaryResult> GetAvatarStatesByOffsetSrh( + public UnaryResult> GetAvatarStatesByWorldSrh( IEnumerable addressBytesList, - byte[] stateRootHashBytes) + byte[] worldStateRootHashBytes) { - var stateRootHash = new HashDigest(stateRootHashBytes); + var stateRootHash = new HashDigest(worldStateRootHashBytes); var addresses = addressBytesList.Select(a => new Address(a)).ToList(); var worldState = _blockChain.GetWorldState(stateRootHash); var avatarStates = addresses.Select(address => AvatarModule.GetAvatarState(worldState, address)); @@ -178,11 +176,11 @@ public UnaryResult> GetStateBulk( return new UnaryResult>(result); } - public UnaryResult> GetStateBulkBySrh( + public UnaryResult> GetStateBulk( IEnumerable addressBytesList, - byte[] stateRootHashBytes) + byte[] accountStateRootHashBytes) { - var stateRootHash = new HashDigest(stateRootHashBytes); + var stateRootHash = new HashDigest(accountStateRootHashBytes); var result = new Dictionary(); Address[] addresses = addressBytesList.Select(b => new Address(b)).ToArray(); IReadOnlyList values = _blockChain.GetAccountState(stateRootHash).GetStates(addresses); @@ -194,13 +192,32 @@ public UnaryResult> GetStateBulkBySrh( return new UnaryResult>(result); } - public UnaryResult GetBalance(byte[] addressBytes, byte[] currencyBytes, byte[] blockHashBytes) + public UnaryResult> GetStateBulkByWorldSrh( + IEnumerable addressBytesList, + byte[] accountBytes, + byte[] worldtStateRootHashBytes) + { + var stateRootHash = new HashDigest(worldtStateRootHashBytes); + var accountAddress = new Address(accountBytes); + var result = new Dictionary(); + Address[] addresses = addressBytesList.Select(b => new Address(b)).ToArray(); + IReadOnlyList values = _blockChain.GetWorldState(stateRootHash).GetAccount(accountAddress).GetStates(addresses); + for (int i = 0; i < addresses.Length; i++) + { + result.TryAdd(addresses[i].ToByteArray(), _codec.Encode(values[i] ?? Null.Value)); + } + + return new UnaryResult>(result); + } + + public UnaryResult GetBalance(byte[] addressBytes, byte[] currencyBytes, byte[] accountBytes, byte[] blockHashBytes) { var address = new Address(addressBytes); var serializedCurrency = (Bencodex.Types.Dictionary)_codec.Decode(currencyBytes); Currency currency = CurrencyExtensions.Deserialize(serializedCurrency); + var accountAddress = new Address(accountBytes); var hash = new BlockHash(blockHashBytes); - FungibleAssetValue balance = LegacyModule.GetBalance(_blockChain.GetWorldState(hash), address, currency); + FungibleAssetValue balance = _blockChain.GetWorldState(hash).GetAccount(accountAddress).GetBalance(address, currency); byte[] encoded = _codec.Encode( new Bencodex.Types.List( new IValue[] @@ -213,7 +230,7 @@ public UnaryResult GetBalance(byte[] addressBytes, byte[] currencyBytes, return new UnaryResult(encoded); } - public UnaryResult GetBalanceBySrh(byte[] addressBytes, byte[] currencyBytes, byte[] stateRootHashBytes) + public UnaryResult GetBalance(byte[] addressBytes, byte[] currencyBytes, byte[] stateRootHashBytes) { var address = new Address(addressBytes); var stateRootHash = new HashDigest(stateRootHashBytes); diff --git a/NineChronicles.RPC.Shared b/NineChronicles.RPC.Shared index 067cdadd9..5d2e5b6ce 160000 --- a/NineChronicles.RPC.Shared +++ b/NineChronicles.RPC.Shared @@ -1 +1 @@ -Subproject commit 067cdadd97124c726823281e6b12c976d4c9eebe +Subproject commit 5d2e5b6ce8023215702df088cef53f10a239b0da