Skip to content

Commit

Permalink
Update PeerStatus to use generic record format
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 2, 2024
1 parent 255f649 commit f1bc178
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions convex-core/src/main/java/convex/core/cvm/PeerStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ public PeerStatus withPeerStake(long newStake) {
if (peerStake == newStake) return this;
long stakeChange=newStake-peerStake;

return new PeerStatus(controller, newStake, stakes, delegatedStake, metadata,timestamp,balance+stakeChange);
return new PeerStatus(controller, newStake, getStakes(), delegatedStake, getMetadata(),timestamp,balance+stakeChange);
}

public PeerStatus withPeerData(AHashMap<ACell,ACell> newMeta) {
if (metadata==newMeta) return this;
return new PeerStatus(controller, peerStake, stakes, delegatedStake, newMeta,timestamp,balance);
return new PeerStatus(controller, peerStake, getStakes(), delegatedStake, newMeta,timestamp,balance);
}

@Override
Expand All @@ -283,12 +283,12 @@ public void validateCell() throws InvalidDataException {
@Override
public ACell get(Keyword key) {
if (Keywords.CONTROLLER.equals(key)) return controller;
if (Keywords.STAKE.equals(key)) return CVMLong.create(peerStake);
if (Keywords.STAKE.equals(key)) return values.get(1);
if (Keywords.STAKES.equals(key)) return getStakes();
if (Keywords.DELEGATED_STAKE.equals(key)) return CVMLong.create(delegatedStake);
if (Keywords.DELEGATED_STAKE.equals(key)) return values.get(3);
if (Keywords.METADATA.equals(key)) return getMetadata();
if (Keywords.TIMESTAMP.equals(key)) return CVMLong.create(timestamp);
if (Keywords.BALANCE.equals(key)) return CVMLong.create(balance);
if (Keywords.TIMESTAMP.equals(key)) return values.get(5);
if (Keywords.BALANCE.equals(key)) return values.get(6);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package convex.core.data;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import convex.core.cvm.Address;
import convex.core.cvm.Keywords;
import convex.core.cvm.PeerStatus;
import convex.core.data.prim.CVMLong;
import convex.core.exceptions.InvalidDataException;
import convex.core.util.Utils;

public class PeerStatusTest {

@Test public void testEmpty() {
PeerStatus ps=PeerStatus.create(null, 0);

assertEquals(CVMLong.ZERO,ps.get(Keywords.DELEGATED_STAKE));
doPeerStatusTest(ps);
}

Expand Down

0 comments on commit f1bc178

Please sign in to comment.