Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async getReputation({
skillId,
address,
}: {
skillId: number,
address: Address,
} = {}) {
assert(Number.isFinite(skillId), 'skillId must be a number');
assert(isValidAddress(address), 'address must be an address');
// Throw error if private network
if (typeof this.network === 'undefined') {
throw new Error('This method is not supported on a private network');
}
// Throw error if not goerli or mainnet
if (
this.network !== 'goerli' &&
this.network !== 'mainnet' &&
this.network !== 'homestead'
) {
throw new Error('This method is only supported on goerli or mainnet');
}
// Get the current reputation root hash
const parseReturnValue = (value: any, type: ParamTypes) => {
switch (type) {
case 'number':
if (isBigNumber(value)) return value.toNumber();
assert(Number(value) === value, `Unexpected value "${value}"`);
return value;
case 'address':
// Filter out empty addresses
return isValidAddress(value) ? value : null;
default:
return value;
}
};
async getReputation({
skillId = 1,
user,
}: {
skillId: number,
user: Address,
} = {}) {
assert(Number.isFinite(skillId), 'skillId must be a number');
assert(isValidAddress(user), 'user must be an address');
if (this.network !== 'rinkeby')
throw new Error(
'Reputation is currently only supported for contracts on Rinkeby',
);
const response = await fetch(
`https://colony.io/reputation/${this.network}/${
this.contract.address
}]/${skillId}/${user}`,
);
return response.json();
}
}
async getTokenLockingClient() {
const { address } = await this.getTokenLockingAddress.call();
if (!isValidAddress(address))
throw new Error(`TokenLocking contract could not be found`);
return this.getTokenLockingClientByAddress(address);
}
convertOutput(value) {
return isValidAddress(value) ? value : null;
},
convertInput: passThrough,
makeExecuteTaskRoleChange('setTaskWorkerRole', async ({ taskId }) => {
const { address } = await this.getTaskRole.call({
taskId,
role: TASK_ROLE_WORKER,
});
if (isValidAddress(address))
throw new Error('Unable to set task role; worker is already set');
return null;
});
}
return value.map(element => (isValidAddress(element) ? element : null));
},
static _validatePayload(payload: any) {
const assert = makeAssert('Invalid payload');
assert(isPlainObject(payload), 'Payload must be an object');
const { data, destinationAddress, sourceAddress, value } = payload || {};
assert(isHexStrict(data), 'data must be a hex string');
assert(
isValidAddress(destinationAddress),
'destinationAddress must be a valid address',
);
assert(
isValidAddress(sourceAddress),
'sourceAddress must be a valid address',
);
return assert(
Number(value) === value && value >= 0,
'value must be a positive number',
);
}