Skip to content

Commit

Permalink
Merge pull request #570 from Atralupus/fix/stake-state-version
Browse files Browse the repository at this point in the history
Just store stake type in state
  • Loading branch information
Atralupus authored Dec 22, 2024
2 parents 292d1e5 + b7dd089 commit 6e5ed2d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
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() { }

Check warning on line 23 in Lib9c.Models/States/StakeState.cs

View workflow job for this annotation

GitHub Actions / Test (Mimir.MongoDB.Tests)

Non-nullable property 'Contract' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[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));

0 comments on commit 6e5ed2d

Please sign in to comment.