Skip to content

Commit

Permalink
Merge pull request #2479 from greymistcube/bump/libplanet-to-4.2.0
Browse files Browse the repository at this point in the history
⬆️ Bump libplanet to 4.2.0
  • Loading branch information
greymistcube authored Mar 25, 2024
2 parents 2e402a3 + 3f278b5 commit 757b1ca
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 253 deletions.
15 changes: 15 additions & 0 deletions .Lib9c.Tests/Action/Common/MockWorldState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public MockWorldState SetAccountState(Address address, IAccountState accountStat
public MockWorldState SetState(Address accountAddress, Address address, IValue state)
=> SetAccountState(accountAddress, GetMockAccountState(accountAddress).SetState(address, state));

public FungibleAssetValue GetBalance(Address address, Currency currency)
=> GetAccountState(ReservedAddresses.LegacyAccount).Trie.Get(MockKeyConverters.ToFungibleAssetKey(address, currency)) is Integer value
? FungibleAssetValue.FromRawValue(currency, value)
: currency * 0;

public MockWorldState SetBalance(
Address address,
FungibleAssetValue amount)
Expand Down Expand Up @@ -128,6 +133,11 @@ public MockWorldState TransferBalance(
=> SubtractBalance(sender, currency, rawAmount)
.AddBalance(recipient, currency, rawAmount);

public FungibleAssetValue GetTotalSupply(Currency currency)
=> GetAccountState(ReservedAddresses.LegacyAccount).Trie.Get(MockKeyConverters.ToTotalSupplyKey(currency)) is Integer value
? FungibleAssetValue.FromRawValue(currency, value)
: currency * 0;

public MockWorldState SetTotalSupply(FungibleAssetValue amount)
=> SetTotalSupply(amount.Currency, amount.RawValue);

Expand Down Expand Up @@ -155,6 +165,11 @@ public MockWorldState SubtractTotalSupply(Currency currency, BigInteger rawAmoun
GetMockAccountState(ReservedAddresses.LegacyAccount)
.SubtractTotalSupply(currency, rawAmount));

public ValidatorSet GetValidatorSet()
=> GetMockAccountState(ReservedAddresses.LegacyAccount).Trie.Get(MockKeyConverters.ValidatorSetKey) is { } value
? new ValidatorSet(value)
: new ValidatorSet();

public MockWorldState SetValidator(Validator validator)
=> SetAccountState(
ReservedAddresses.LegacyAccount,
Expand Down
1 change: 0 additions & 1 deletion .Lib9c.Tests/Policy/BlockPolicyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ public void EarnMiningGoldWhenSuccessMining()
blockChain.Append(block, GenerateBlockCommit(block, adminPrivateKey));
FungibleAssetValue actualBalance = blockChain
.GetWorldState()
.GetAccountState(ReservedAddresses.LegacyAccount)
.GetBalance(adminAddress, _currency);
FungibleAssetValue expectedBalance = new FungibleAssetValue(_currency, 10, 0);
Assert.True(expectedBalance.Equals(actualBalance));
Expand Down
2 changes: 0 additions & 2 deletions .Lib9c.Tools/SubCommand/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public void Balance(
FungibleAssetValue balance =
chain
.GetWorldState(offset.Hash)
.GetAccountState(ReservedAddresses.LegacyAccount)
.GetBalance(addr, gold);
Console.WriteLine("{0}\t{1}", addr, balance);
return;
Expand Down Expand Up @@ -94,7 +93,6 @@ i.GoldDistributions is Bencodex.Types.List l
FungibleAssetValue balance =
chain
.GetWorldState(offset.Hash)
.GetAccountState(ReservedAddresses.LegacyAccount)
.GetBalance(addr, gold);
Console.WriteLine("{0}\t{1}", addr, balance);
printed.Add(addr);
Expand Down
2 changes: 1 addition & 1 deletion .Libplanet
Submodule .Libplanet updated 66 files
+1 −0 .github/bin/constants.sh
+1 −2 .github/workflows/benchmarks-merged.yml
+1 −2 .github/workflows/benchmarks-pr.yml
+51 −8,837 CHANGES.md
+4 −0 CONTRIBUTING.md
+10 −8 Docs/docfx.json
+6 −6 Libplanet.Action.Tests/ActionContextTest.cs
+3 −3 Libplanet.Action.Tests/ActionEvaluationTest.cs
+12 −12 Libplanet.Action.Tests/Common/DumbAction.cs
+12 −12 Libplanet.Action.Tests/Common/DumbModernAction.cs
+2 −7 Libplanet.Action.Tests/Common/SetValidator.cs
+1 −0 Libplanet.Action.Tests/Libplanet.Action.Tests.csproj
+0 −201 Libplanet.Action.Tests/Mocks/MockAccountState.cs
+0 −65 Libplanet.Action.Tests/Mocks/MockWorldState.cs
+4 −6 Libplanet.Action.Tests/Sys/InitializeTest.cs
+5 −10 Libplanet.Action/ActionEvaluator.cs
+2 −0 Libplanet.Action/AssemblyInfo.cs
+7 −8 Libplanet.Action/FeeCollector.cs
+7 −243 Libplanet.Action/State/Account.cs
+15 −169 Libplanet.Action/State/AccountDiff.cs
+0 −24 Libplanet.Action/State/AccountState.cs
+2 −2 Libplanet.Action/State/CurrencyPermissionException.cs
+0 −103 Libplanet.Action/State/IAccount.cs
+0 −33 Libplanet.Action/State/IAccountState.cs
+100 −12 Libplanet.Action/State/IWorld.cs
+0 −22 Libplanet.Action/State/IWorldDelta.cs
+33 −0 Libplanet.Action/State/IWorldState.cs
+2 −2 Libplanet.Action/State/InsufficientBalanceException.cs
+1 −1 Libplanet.Action/State/SupplyOverflowException.cs
+2 −2 Libplanet.Action/State/TotalSupplyNotTrackableException.cs
+265 −7 Libplanet.Action/State/World.cs
+38 −0 Libplanet.Action/State/WorldBaseState.cs
+5 −34 Libplanet.Action/State/WorldDelta.cs
+0 −16 Libplanet.Action/State/WorldExtensions.cs
+3 −3 Libplanet.Action/Sys/Initialize.cs
+2 −2 Libplanet.Explorer.Tests/GeneratedBlockChainFixture.cs
+1 −0 Libplanet.Explorer.Tests/Libplanet.Explorer.Tests.csproj
+14 −14 Libplanet.Explorer.Tests/Queries/StateQueryTest.Legacy.cs
+36 −165 Libplanet.Explorer.Tests/Queries/StateQueryTest.Mocks.cs
+2 −6 Libplanet.Explorer.Tests/Queries/StateQueryTest.cs
+0 −6 Libplanet.Explorer/Queries/StateQuery.cs
+55 −0 Libplanet.Mocks/Libplanet.Mocks.csproj
+32 −0 Libplanet.Mocks/MockUtil.cs
+256 −0 Libplanet.Mocks/MockWorldState.cs
+0 −1 Libplanet.Net.Tests/Consensus/ContextTest.cs
+0 −1 Libplanet.Net.Tests/TestUtils.cs
+0 −1 Libplanet.Net/Consensus/ConsensusContext.cs
+0 −72 Libplanet.Tests/Action/AccountDiffTest.cs
+11 −317 Libplanet.Tests/Action/AccountTest.cs
+4 −36 Libplanet.Tests/Action/ActionEvaluatorTest.cs
+339 −0 Libplanet.Tests/Action/WorldTest.cs
+6 −15 Libplanet.Tests/Action/WorldV0Test.cs
+39 −45 Libplanet.Tests/Action/WorldV1Test.cs
+15 −18 Libplanet.Tests/Blockchain/BlockChainTest.Append.cs
+0 −4 Libplanet.Tests/Blockchain/BlockChainTest.cs
+2 −2 Libplanet.Tests/Blockchain/Renderers/AnonymousActionRendererTest.cs
+2 −2 Libplanet.Tests/Blockchain/Renderers/LoggedActionRendererTest.cs
+1 −0 Libplanet.Tests/Libplanet.Tests.csproj
+20 −0 Libplanet.sln
+0 −1 Libplanet/Blockchain/BlockChain.Validate.cs
+1 −4 Libplanet/Blockchain/Policies/NullBlockPolicy.cs
+1 −1 Libplanet/Libplanet.csproj
+7,143 −0 changes/v0.md
+636 −0 changes/v1.md
+401 −0 changes/v2.md
+657 −0 changes/v3.md
9 changes: 0 additions & 9 deletions .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@ public RemoteAccount(IAccountState baseState)

public ITrie Trie => _baseState.Trie;

public FungibleAssetValue GetBalance(Address address, Currency currency)
=> _baseState.GetBalance(address, currency);

public IValue? GetState(Address address)
=> _baseState.GetState(address);

public IReadOnlyList<IValue?> GetStates(IReadOnlyList<Address> addresses)
=> _baseState.GetStates(addresses);

public FungibleAssetValue GetTotalSupply(Currency currency)
=> _baseState.GetTotalSupply(currency);

public ValidatorSet GetValidatorSet()
=> _baseState.GetValidatorSet();

public IAccount MintAsset(IActionContext context, Address recipient, FungibleAssetValue value)
{
throw new NotSupportedException();
Expand Down
169 changes: 0 additions & 169 deletions .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccountState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.Store.Trie;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Consensus;

namespace Libplanet.Extensions.RemoteBlockChainStates;

Expand Down Expand Up @@ -121,131 +119,6 @@ public RemoteAccountState(
return response.Data.StateQuery.States is { } state ? codec.Decode(state) : null;
}

public FungibleAssetValue GetBalance(Address address, Currency currency)
{
object? currencyInput = currency.TotalSupplyTrackable ? new
{
ticker = currency.Ticker,
decimalPlaces = currency.DecimalPlaces,
minters = currency.Minters?.Select(addr => addr.ToString()).ToArray(),
totalSupplyTrackable = currency.TotalSupplyTrackable,
maximumSupplyMajorUnit = currency.MaximumSupply.Value.MajorUnit,
maximumSupplyMinorUnit = currency.MaximumSupply.Value.MinorUnit,
} : new
{
ticker = currency.Ticker,
decimalPlaces = currency.DecimalPlaces,
minters = currency.Minters?.Select(addr => addr.ToString()).ToArray(),
totalSupplyTrackable = currency.TotalSupplyTrackable,
};
var response = _graphQlHttpClient.SendQueryAsync<GetBalanceResponseType>(
new GraphQLRequest(
@"query GetBalance(
$owner: Address!,
$currency: CurrencyInput!,
$accountStateRootHash: HashDigest_SHA256!)
{
stateQuery
{
balance(
owner: $owner,
currency: $currency,
accountStateRootHash: $accountStateRootHash)
{
string
}
}
}",
operationName: "GetBalance",
variables: new
{
owner = address.ToString(),
currency = currencyInput,
accountStateRootHash = Trie.Hash is { } accountSrh
? ByteUtil.Hex(accountSrh.ByteArray)
: null,
})).Result;

return FungibleAssetValue.Parse(currency, response.Data.StateQuery.Balance.String.Split()[0]);
}

public FungibleAssetValue GetTotalSupply(Currency currency)
{
object? currencyInput = currency.TotalSupplyTrackable ? new
{
ticker = currency.Ticker,
decimalPlaces = currency.DecimalPlaces,
minters = currency.Minters.Select(addr => addr.ToString()).ToArray(),
totalSupplyTrackable = currency.TotalSupplyTrackable,
maximumSupplyMajorUnit = currency.MaximumSupply.Value.MajorUnit,
maximumSupplyMinorUnit = currency.MaximumSupply.Value.MinorUnit,
} : new
{
ticker = currency.Ticker,
decimalPlaces = currency.DecimalPlaces,
minters = currency.Minters.Select(addr => addr.ToString()).ToArray(),
totalSupplyTrackable = currency.TotalSupplyTrackable,
};
var response = _graphQlHttpClient.SendQueryAsync<GetTotalSupplyResponseType>(
new GraphQLRequest(
@"query GetTotalSupply(
$currency: CurrencyInput!,
$accountStateRootHash: HashDigest_SHA256!)
{
stateQuery
{
totalSupply(
currency: $currency,
offsetBlockHash: $offsetBlockHash
accountStateRootHash: $accountStateRootHash)
{
string
}
}
}",
operationName: "GetTotalSupply",
variables: new
{
currency = currencyInput,
accountStateRootHash = Trie.Hash is { } accountSrh
? ByteUtil.Hex(accountSrh.ByteArray)
: null,
})).Result;

return FungibleAssetValue.Parse(currency, response.Data.StateQuery.TotalSupply.String.Split()[0]);
}

public ValidatorSet GetValidatorSet()
{
var response = _graphQlHttpClient.SendQueryAsync<GetValidatorsResponseType>(
new GraphQLRequest(
@"query GetValidators(
$accountStateRootHash: HashDigest_SHA256!)
{
stateQuery
{
validators(
accountStateRootHash: $accountStateRootHash)
{
publicKey
power
}
}
}",
operationName: "GetValidators",
variables: new
{
accountStateRootHash = Trie.Hash is { } accountSrh
? ByteUtil.Hex(accountSrh.ByteArray)
: null,
})).Result;

return new ValidatorSet(response.Data.StateQuery.Validators
.Select(x =>
new Validator(new PublicKey(ByteUtil.ParseHex(x.PublicKey)), x.Power))
.ToList());
}

private class GetAccountStateResponseType
{
public StateQueryWithAccountStateType StateQuery { get; set; }

Check warning on line 124 in .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccountState.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Non-nullable property 'StateQuery' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 124 in .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccountState.cs

View workflow job for this annotation

GitHub Actions / nuget

Non-nullable property 'StateQuery' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 124 in .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccountState.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Non-nullable property 'StateQuery' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Expand All @@ -270,46 +143,4 @@ private class StateQueryWithStatesType
{
public byte[] States { get; set; }

Check warning on line 144 in .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccountState.cs

View workflow job for this annotation

GitHub Actions / build-for-unity

Non-nullable property 'States' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 144 in .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccountState.cs

View workflow job for this annotation

GitHub Actions / nuget

Non-nullable property 'States' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 144 in .Libplanet.Extensions.RemoteBlockChainStates/RemoteAccountState.cs

View workflow job for this annotation

GitHub Actions / build-and-test (Release)

Non-nullable property 'States' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}

private class GetBalanceResponseType
{
public StateQueryWithBalanceType StateQuery { get; set; }
}

private class StateQueryWithBalanceType
{
public FungibleAssetValueWithStringType Balance { get; set; }
}

private class FungibleAssetValueWithStringType
{
public string String { get; set; }
}

private class GetTotalSupplyResponseType
{
public StateQueryWithTotalSupplyType StateQuery { get; set; }
}

private class StateQueryWithTotalSupplyType
{
public FungibleAssetValueWithStringType TotalSupply { get; set; }
}

private class GetValidatorsResponseType
{
public StateQueryWithValidatorsType StateQuery { get; set; }
}

private class StateQueryWithValidatorsType
{
public ValidatorType[] Validators { get; set; }
}

private class ValidatorType
{
public string PublicKey { get; set; }

public long Power { get; set; }
}
}
Loading

0 comments on commit 757b1ca

Please sign in to comment.