Testnet Mode — switch back to Production in the menuheader when you're done.
VarnirUserMod extends Event
/**
* Voting round: refuses recovered or frozen identities (social-recovery guard) and an
* `$i.admin` whose volatile has neither `admin` nor `minigate` set.
*
* @returns {Promise<boolean>}
* @memberof VarnirUserMod
*/ public vote(): Promise<boolean> {
return new Promise<boolean>(async (resolve, reject) => {
// Social recovery (spec §4.5): a recovered identity is dead, a frozen one cannot move money.
const recoveryRefusal = this.refuseRecoveredStreams([]);
if (recoveryRefusal) return reject(recoveryRefusal);
// The Owner of the keys / partitions (Will provide transaction information)
const admin = this.getActivityStreams(this.transactions.$i.admin);
const adminTmpState = await admin.getVolatile();
if (!adminTmpState.admin && !adminTmpState.minigate) {
return reject("User not allowed to trigger confirmation, check system vol");
}
// It is now a mod multiplier so figures can be different.
// const depositPercent = this.transactions.$i.admin.depositFeePercent;
// if (adminTmpState.admin === "minigate" || adminTmpState.minigate) {
// // Minigate is going to be "open" so limit what it can do
// //Prevent 3rd party abuse so set an upper limit (as we can always return)
// if (depositPercent > 0.3) {
// return reject("Deposit Percent Fee cannot be more than 0.3");
// }
// // It can never be set to less than our default via a minigate
// if (depositPercent < 0.1) {
// return reject("Deposit Percent Fee cannot be less than 0.1");
// }
// } else {
// // Another type of admin such as back office restrictions
// if (depositPercent > 0.1) {
// return reject("Deposit Percent Fee cannot be more than 0.1");
// }
// if (depositPercent < 0.05) {
// return reject("Deposit Percent Fee cannot be less than 0.05");
// }
// }
resolve(true);
});
}/**
* Commit round: writes `$i.admin.depositFeePercent` and this umid
* (`depositFeePercentUmid`) onto `$o.user`.
*
* @returns {Promise<any>}
* @memberof VarnirUserMod
*/ public commit(): Promise<any> {
return new Promise<any>(async (resolve, reject) => {
const user = this.getActivityStreams(this.transactions.$o.user);
const userState = user.getState();
userState.depositFeePercent = this.transactions.$i.admin.depositFeePercent;
userState.depositFeePercentUmid = this.umid;
user.setState(userState);
resolve(true);
});
} private refuseRecoveredIdentity(state: any, outgoing: boolean): string | null {
if (state && state.recoveredTo) {
// A dead identity may still RECEIVE: the credit lands and is swept to recoveredTo.
return outgoing
? `Identity recovered - new identity is ${state.recoveredTo}; your keys are still valid`
: null;
}
if (outgoing && state && state.recovery && state.recovery.frozen) {
return "Identity frozen - a social recovery is in its 48h waiting period";
}
return null;
} private refuseRecoveredStreams(incomingOnly: string[] | "all-outputs"): string | null {
// Never getActivityStreams(ref): an unloaded ref CREATES a stream. The
// no-argument form returns only the streams this transaction loaded.
const ctx: any = this as any;
const loaded: any = ctx.getActivityStreams() || {};
const outputs: any = (ctx.transactions && ctx.transactions.$o) || {};
const toId = (label: string, ref: any): string | null => {
const raw = ref && typeof ref === "object" ? ref.$stream : typeof ref === "string" ? ref : /^[0-9a-f]{64}$/i.test(label) ? label : null;
return typeof raw === "string" ? raw.split(":")[0].slice(-64) : null;
};
const outputIds: string[] = [];
const incomingIds: string[] = [];
for (const label of Object.keys(outputs)) {
const id = toId(label, outputs[label]);
if (!id) continue;
outputIds.push(id);
if (incomingOnly === "all-outputs" || incomingOnly.indexOf(label) !== -1) incomingIds.push(id);
}
for (const id of Object.keys(loaded)) {
const activity = loaded[id];
if (!activity || typeof activity.getState !== "function") continue;
const signed = typeof activity.hasSignature === "function" && activity.hasSignature();
const incoming = !signed && outputIds.indexOf(id) !== -1 && incomingIds.indexOf(id) !== -1;
const refusal = this.refuseRecoveredIdentity(activity.getState(), !incoming);
if (refusal) return refusal;
}
return null;
}