chore(smart-contracts): remove redundant ascii to hex in favour of ethers hexlify (#3066)

This commit is contained in:
Edd 2023-03-03 12:21:22 +00:00 committed by GitHub
parent 96bf12d4dd
commit acd96fbf21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 23 deletions

View File

@ -1,6 +1,6 @@
import { ethers } from 'ethers';
import { hexlify } from 'ethers/lib/utils';
import abi from '../abis/claim_abi.json';
import { asciiToHex } from '../utils';
export const UNSPENT_CODE = '0x0000000000000000000000000000000000000000';
export const SPENT_CODE = '0x0000000000000000000000000000000000000001';
@ -71,7 +71,7 @@ export class Claim {
tranche,
expiry,
},
asciiToHex(country),
hexlify(country),
target,
].filter(Boolean)
);
@ -109,9 +109,7 @@ export class Claim {
* @return {Promise<boolean>}
*/
async isCountryBlocked(country: string): Promise<boolean> {
const isAllowed = await this.contract.allowed_countries(
asciiToHex(country)
);
const isAllowed = await this.contract.allowed_countries(hexlify(country));
return !isAllowed;
}
}

View File

@ -1,17 +0,0 @@
/**
* From:
* https://github.com/ChainSafe/web3.js/blob/436e77a8eaa061fbaa183a9f73ca590c2e1d7697/packages/web3-utils/src/index.js
*/
export const asciiToHex = (str: string) => {
if (!str) return '0x00';
let hex = '';
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i);
const n = code.toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return '0x' + hex;
};

View File

@ -1,2 +1 @@
export * from './ascii-to-hex';
export * from './prepend-0x';