Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getSmartContractInit(addr: string): Promise> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
return this.provider.send(
RPCMethod.GetSmartContractInit,
address.replace('0x', '').toLowerCase(),
);
}
]
for (let index = 0; index < neededParams.length; index++) {
const param = neededParams[index]
if (!(param in payload)) {
throw new Error(
errorsCode.WrongRequiredparam + param
)
}
}
const storage = new BrowserStorage()
let forConfirm = await storage.get(FIELDS.CONFIRM_TX)
if (validation.isBech32(payload.toAddr)) {
payload.toAddr = fromBech32Address(payload.toAddr)
}
payload.toAddr = toChecksumAddress(payload.toAddr)
try {
forConfirm.push(payload)
} catch (err) {
forConfirm = [payload]
}
await storage.set(
new BuildObject(FIELDS.CONFIRM_TX, forConfirm)
)
this.notificationsCounter(forConfirm)
getBalance(addr: string): Promise> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
return this.provider.send(
RPCMethod.GetBalance,
address.replace('0x', '').toLowerCase(),
);
}
private getAddressType() {
const addrBool = validation.isAddress(this.raw);
const base58Bool = validation.isBase58(this.raw);
const bech32Bool = validation.isBech32(this.raw);
const bech32TestNetBool = validation.isBech32TestNet(this.raw);
const checksumBool = isValidChecksumAddress(this.raw);
if (addrBool === true && checksumBool === false) {
this.addressType = AddressType.bytes20;
this.bytes20 = this.raw.startsWith('0x')
? this.raw.substring(2)
: this.raw;
return;
}
if (addrBool === true && checksumBool === true) {
this.addressType = AddressType.checkSum;
this.bytes20 = this.raw.toLowerCase().substring(2);
return;
}
getSmartContractSubState(
addr: string,
variableName: string,
indices?: string[],
): Promise> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
if (!variableName) {
throw new Error('Variable name required');
}
return this.provider.send(
RPCMethod.GetSmartContractSubState,
address.replace('0x', '').toLowerCase(),
variableName,
indices === undefined ? [] : indices,
);
}
export const normaliseAddress = (address: string): string => {
if (validation.isBech32(address)) {
return fromBech32Address(address);
}
return toChecksumAddress(address);
};
isAddress() {
if (this.to === null) {
return null;
}
const isBech32 = validation.isBech32(this.to);
if (isBech32) {
return false;
}
return ERRORCODE[2];
},
isAmount() {
getSmartContractState(addr: string): Promise> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
return this.provider.send(
RPCMethod.GetSmartContractState,
address.replace('0x', '').toLowerCase(),
);
}
getSmartContracts(
addr: string,
): Promise, string>> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
return this.provider.send(
RPCMethod.GetSmartContracts,
address.replace('0x', '').toLowerCase(),
);
}