Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/main/java/com/github/iotexproject/antenna/action/Envelop.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class Envelop {
private StakeTransferOwnership stakeTransferOwnership;
private CandidateRegister candidateRegister;
private CandidateBasicInfo candidateUpdate;
private SetVoterRewardOptIn setVoterRewardOptIn;
private SetVoterRewardDestination setVoterRewardDestination;
private StartSubChain startSubChain;
private StopSubChain stopSubChain;
private PutBlock putBlock;
Expand Down Expand Up @@ -141,6 +143,17 @@ public static Envelop deserialize(byte[] bytes) throws IllegalArgumentException
if (core.getCandidateUpdate().toByteArray().length > 0) {
envelop.setCandidateUpdate(core.getCandidateUpdate());
}
// hasX(), not toByteArray().length: SetVoterRewardOptIn carries no
// payload -- the sender is the delegate -- so it serializes to zero
// bytes and a length check drops it silently. The oneof's presence
// bit is the only thing that distinguishes "opt in" from "no action
// set at all".
if (core.hasSetVoterRewardOptIn()) {
envelop.setSetVoterRewardOptIn(core.getSetVoterRewardOptIn());
}
if (core.hasSetVoterRewardDestination()) {
envelop.setSetVoterRewardDestination(core.getSetVoterRewardDestination());
}

return envelop;
} catch (InvalidProtocolBufferException e) {
Expand Down Expand Up @@ -211,6 +224,12 @@ public ActionCore core() {
if (candidateUpdate != null) {
builder.setCandidateUpdate(candidateUpdate);
}
if (setVoterRewardOptIn != null) {
builder.setSetVoterRewardOptIn(setVoterRewardOptIn);
}
if (setVoterRewardDestination != null) {
builder.setSetVoterRewardDestination(setVoterRewardDestination);
}
if (startSubChain != null) {
builder.setStartSubChain(startSubChain);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.iotexproject.antenna.action.method;

import com.github.iotexproject.antenna.action.Envelop;
import com.github.iotexproject.antenna.crypto.Bech32;
import com.github.iotexproject.antenna.protocol.SetVoterRewardDestinationRequest;
import com.github.iotexproject.antenna.rpc.RPCMethod;
import com.github.iotexproject.grpc.types.Action;
import com.github.iotexproject.grpc.types.SetVoterRewardDestination;
import com.google.protobuf.ByteString;

/**
* SetVoterRewardDestination method.
*
* <p>The protocol reads the recipient with address.FromBytes, so the io1...
* string is decoded to its 20 raw bytes here. Sending the bech32 text instead
* produces an action that signs and is then rejected on decode.
*/
public class SetVoterRewardDestinationMethod extends AbstractMethod {
private final SetVoterRewardDestinationRequest request;
private final Envelop envelop;

public SetVoterRewardDestinationMethod(RPCMethod client, SetVoterRewardDestinationRequest request) {
super(client, request.getAccount());
this.request = request;
this.envelop = baseEnvelop(request);
}

private SetVoterRewardDestination payload() {
byte[] dec = Bech32.decode(request.getRecipient()).data;
byte[] raw = Bech32.convertBits(dec, 0, dec.length, 5, 8, false);
return SetVoterRewardDestination.newBuilder()
.setRecipient(ByteString.copyFrom(raw))
.build();
}

@Override
public String execute() {
envelop.setSetVoterRewardDestination(payload());
return sendAction(envelop);
}

public Action signedAction() {
envelop.setSetVoterRewardDestination(payload());
return signAction(envelop).action();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.iotexproject.antenna.action.method;

import com.github.iotexproject.antenna.action.Envelop;
import com.github.iotexproject.antenna.protocol.SetVoterRewardOptInRequest;
import com.github.iotexproject.antenna.rpc.RPCMethod;
import com.github.iotexproject.grpc.types.Action;
import com.github.iotexproject.grpc.types.SetVoterRewardOptIn;

/**
* SetVoterRewardOptIn method.
*
* <p>Opts the sending delegate into IIP-59 protocol-native voter reward
* distribution. The message is empty by design -- the sender is the delegate --
* so it must be set on the envelope explicitly rather than left to a
* "non-empty payload" check, which would drop it.
*/
public class SetVoterRewardOptInMethod extends AbstractMethod {
private final Envelop envelop;

public SetVoterRewardOptInMethod(RPCMethod client, SetVoterRewardOptInRequest request) {
super(client, request.getAccount());
this.envelop = baseEnvelop(request);
}

@Override
public String execute() {
envelop.setSetVoterRewardOptIn(SetVoterRewardOptIn.newBuilder().build());
return sendAction(envelop);
}

public Action signedAction() {
envelop.setSetVoterRewardOptIn(SetVoterRewardOptIn.newBuilder().build());
return signAction(envelop).action();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.iotexproject.antenna.protocol;

import lombok.Data;

/**
* setVoterRewardDestination request.
*
* <p>Redirects the sender's own IIP-59 voter rewards. Passing the sender's own
* address clears the override.
*
* <p>The protocol resolves the destination live at drain time rather than
* snapshotting it at the era freeze, so a change made mid-era applies to that
* era's payout. A compound (AutoDeposit) bucket still takes priority over it.
*/
@Data

Check warning on line 15 in src/main/java/com/github/iotexproject/antenna/protocol/SetVoterRewardDestinationRequest.java

View workflow job for this annotation

GitHub Actions / build

Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.
public class SetVoterRewardDestinationRequest extends ActionRequest {
/** Recipient in io1... form; converted to raw bytes on the wire. */
private String recipient;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.iotexproject.antenna.protocol;

import lombok.Data;

/**
* setVoterRewardOptIn request.
*
* <p>Carries no fields of its own: the sender is the delegate opting in. It is
* one-way -- the protocol has no counterpart action to opt back out.
*
* <p>Opting in with no reward portions published on the DelegateProfile
* contract is silently harmful rather than rejected. The protocol cannot tell
* "unset" from "explicit zero", falls back to a 100% commission, and pays every
* voter zero while producing successful distributions. Publish portions first.
*/
@Data

Check warning on line 16 in src/main/java/com/github/iotexproject/antenna/protocol/SetVoterRewardOptInRequest.java

View workflow job for this annotation

GitHub Actions / build

Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.
public class SetVoterRewardOptInRequest extends ActionRequest {
}
Loading
Loading