Skip to content

Commit

Permalink
Make set-peer-data less strict to allow controllers with different keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Jan 13, 2025
1 parent 98178d1 commit c14cf95
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions convex-core/src/main/java/convex/core/cvm/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -2159,20 +2159,17 @@ public Context setPeerData(AccountKey peerKey, AHashMap<ACell, ACell> data) {

// get the callers account and account status
Address address = getAddress();
AccountStatus as = getAccountStatus(address);

AccountKey ak = as.getAccountKey();
if (ak == null) return withError(ErrorCodes.STATE,"The account signing this transaction must have a public key");
PeerStatus ps=s.getPeer(ak);
if (ps==null) return withError(ErrorCodes.STATE,"Peer does not exist for this account and account key: "+ak.toChecksumHex());
if (!ps.getController().equals(address)) return withError(ErrorCodes.STATE,"Current address "+address+" is not the controller of this peer account");
PeerStatus ps=s.getPeer(peerKey);
if (ps==null) return withError(ErrorCodes.STATE,"Peer does not exist for key: "+peerKey);
if (!Utils.equals(ps.getController(),address)) return withError(ErrorCodes.STATE,"Current address "+address+" is not the controller of this peer account");

Hash lastStateHash = s.getHash();
// TODO: should use complete Map
// at the moment only :url is used in the data map
AHashMap<ACell,ACell> newMeta=data;
PeerStatus updatedPeer=ps.withPeerData(newMeta);
s=s.withPeer(ak, updatedPeer); // adjust peer
s=s.withPeer(peerKey, updatedPeer); // adjust peer

// if no change just return the current context
if (lastStateHash.equals(s.getHash())){
Expand Down

0 comments on commit c14cf95

Please sign in to comment.