Skip to content

Commit 019a359

Browse files
committed
Add evict-peer function stub
1 parent 1831c21 commit 019a359

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

convex-core/src/main/cvx/convex/core/metadata.cvx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,13 @@
548548
{:doc {:description "Like `eval` but evaluates code in the environment of the specifed account. The current account must have controller privileges to execute this operation (see `set-controller`)."
549549
:examples [{:code "(eval-as #666 '(+ 1 2))"}]
550550
:signature [{:params [address form]}]}}
551+
552+
evict-peer
553+
{:doc {:description "Evicts a peer. Peer must be insufficiently staked, or controlled by this account"
554+
:errors {:CAST "If the first argument is not a valid account-key."}
555+
:examples [{:code "(evict-peer peer-key)"}]
556+
:signature [{:params [peer-key]
557+
:return Long}]}}
551558

552559
exp
553560
{:doc {:description "Returns `e` raised to the power of the given numerical argument."

convex-core/src/main/java/convex/core/cvm/impl/InvalidBlockException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import convex.core.exceptions.ValidationException;
44

5+
/**
6+
* Exception thrown when a Block contains invalid structure or data
7+
*/
58
@SuppressWarnings("serial")
69
public class InvalidBlockException extends ValidationException {
710

convex-core/src/main/java/convex/core/lang/Context.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,10 +2041,6 @@ public Context createPeer(AccountKey accountKey, long initialStake) {
20412041

20422042
Address myAddress=getAddress();
20432043

2044-
// TODO: SECURITY fix
2045-
// AccountStatus as=getAccountStatus(myAddress);
2046-
// if (!as.getAccountKey().equals(accountKey)) return this.withArgumentError("Cannot create a peer with a different account-key");
2047-
20482044
long balance=getBalance(myAddress);
20492045
if (initialStake>balance) return this.withFundsError("Insufficient balance ("+balance+") to assign an initial stake of "+initialStake);
20502046

@@ -2055,6 +2051,15 @@ public Context createPeer(AccountKey accountKey, long initialStake) {
20552051
s=s.withPeer(accountKey, newPeerStatus); // add peer
20562052
return withState(s);
20572053
}
2054+
2055+
public Context evictPeer(AccountKey peerKey) {
2056+
State s=getState();
2057+
PeerStatus ps=s.getPeer(peerKey);
2058+
if (ps==null) {
2059+
return this;
2060+
}
2061+
return withError(ErrorCodes.TODO,"Can't evict peers yet!");
2062+
}
20582063

20592064
/**
20602065
* Sets peer data.

convex-core/src/main/java/convex/core/lang/Core.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,19 @@ public Context invoke(Context context, ACell[] args) {
986986
return context.createPeer(accountKey, amount.longValue()).consumeJuice(Juice.PEER_UPDATE);
987987
}
988988
});
989+
990+
public static final CoreFn<CVMLong> EVICT_PEER = reg(new CoreFn<>(Symbols.EVICT_PEER,68) {
991+
992+
@Override
993+
public Context invoke(Context context, ACell[] args) {
994+
if (args.length != 1) return context.withArityError(exactArityMessage(1, args.length));
989995

996+
AccountKey accountKey = RT.ensureAccountKey(args[0]);
997+
if (accountKey == null) return context.withCastError(0,args, Types.BLOB);
998+
999+
return context.evictPeer(accountKey).consumeJuice(Juice.PEER_UPDATE);
1000+
}
1001+
});
9901002

9911003
public static final CoreFn<CVMLong> SET_PEER_DATA = reg(new CoreFn<>(Symbols.SET_PEER_DATA,66) {
9921004

convex-core/src/main/java/convex/core/lang/Symbols.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public class Symbols {
107107
public static final Symbol CREATE_PEER = intern("create-peer");
108108
public static final Symbol SET_PEER_DATA = intern("set-peer-data");
109109
public static final Symbol SET_PEER_STAKE = intern("set-peer-stake");
110+
public static final Symbol EVICT_PEER = intern("evict-peer");
110111

111112
public static final Symbol CALL = intern("call");
112113
public static final Symbol CALL_STAR = intern("call*");
@@ -344,6 +345,7 @@ public class Symbols {
344345

345346

346347

348+
347349

348350

349351

0 commit comments

Comments
 (0)