Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just store stake type in state #570

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions Lib9c.Models/States/StakeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace Lib9c.Models.States;
[BsonIgnoreExtraElements]
public record StakeState : IBencodable
{
public const string StateTypeName = "stake_state";
public const int StateTypeVersion = 3;
public Contract Contract { get; init; }
public string StateTypeName;
public int StateTypeVersion;
public long StartedBlockIndex { get; init; }
public long ReceivedBlockIndex { get; init; }
public StakeState() {}

public StakeState() { }

[BsonIgnore, GraphQLIgnore, JsonIgnore]
public IValue Bencoded =>
Expand All @@ -43,21 +43,10 @@ public StakeState(IValue bencoded)
);
}

if (
l[0] is not Text stateTypeNameValue
|| stateTypeNameValue != StateTypeName
|| l[1] is not Integer stateTypeVersionValue
|| stateTypeVersionValue.Value != StateTypeVersion
)
{
throw new ArgumentException(
nameof(bencoded),
$"{nameof(bencoded)} doesn't have valid header."
);
}

const int reservedCount = 2;

StateTypeName = (Text)l[0];
StateTypeVersion = (Integer)l[1];
Contract = new Contract(l[reservedCount]);
StartedBlockIndex = (Integer)l[reservedCount + 1];
ReceivedBlockIndex = (Integer)l[reservedCount + 2];
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"AgentAddress":"0000000000000000000000000000000000000000","Object":{"Contract":{"StakeRegularFixedRewardSheetTableName":"StakeRegularFixedRewardSheet_V3","StakeRegularRewardSheetTableName":"StakeRegularRewardSheet_V8","RewardInterval":75600,"LockupInterval":302400},"StartedBlockIndex":12047392,"ReceivedBlockIndex":0},"Amount":"0","Metadata":{"SchemaVersion":1,"StoredBlockIndex":0}}
{"AgentAddress":"0000000000000000000000000000000000000000","Object":{"StateTypeName":"stake_state","StateTypeVersion":3,"Contract":{"StakeRegularFixedRewardSheetTableName":"StakeRegularFixedRewardSheet_V3","StakeRegularRewardSheetTableName":"StakeRegularRewardSheet_V8","RewardInterval":75600,"LockupInterval":302400},"StartedBlockIndex":12047392,"ReceivedBlockIndex":0},"Amount":"0","Metadata":{"SchemaVersion":2,"StoredBlockIndex":0}}
2 changes: 1 addition & 1 deletion Mimir.MongoDB/Bson/StakeDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public record StakeDocument(
Address AgentAddress,
StakeState? Object,
BigInteger Amount
) : MimirBsonDocument(Address.ToHex(), new DocumentMetadata(1, StoredBlockIndex));
) : MimirBsonDocument(Address.ToHex(), new DocumentMetadata(2, StoredBlockIndex));
Loading