Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
D4mph1r committed Nov 29, 2024
1 parent 937e11b commit 128d38a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
30 changes: 7 additions & 23 deletions src/handlers/casper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,7 @@ export function casperHandler({
};
},
async getValidatorCount() {
const cep78Client = new CEP78Client(proxy_url + rpc, network);
cep78Client.setContractHash(bridge);
const bn: CLU64 = await cep78Client.contractClient.queryContractData([
"validators_count",
]);
const bn: CLU64 = await bc.queryContractData(["validators_count"]);
return Number(bn);
},
async lockNft(
Expand All @@ -306,10 +302,8 @@ export function casperHandler({
extraArgs,
) {
const nft_storage_exists = await checkStorage(
proxy_url + rpc,
network,
bridge,
sourceNft,
bc,
sourceNft.replace("hash-", ""),
);

const rt_args = RuntimeArgs.fromMap({
Expand Down Expand Up @@ -340,9 +334,7 @@ export function casperHandler({
if (!nft_storage_exists) {
while (true) {
await new Promise((r) => setTimeout(r, 1000));
if (
await checkStorage(proxy_url + rpc, network, bridge, sourceNft)
) {
if (await checkStorage(bc, sourceNft)) {
break;
}
}
Expand Down Expand Up @@ -484,28 +476,20 @@ function convertHashStrToHashBuff(sourceNft: string): Uint8Array {
return Uint8Array.from(Buffer.from(src, "hex"));
}

async function checkStorage(
nodeAddress: string,
network: string,
bridge: string,
sourceNft: string,
) {
const cep78Client = new CEP78Client(nodeAddress, network);
cep78Client.setContractHash(`hash-${bridge}`);

async function checkStorage(bc: Contracts.Contract, sourceNft: string) {
const serializer = Serializer();
const bytes = serializer.storageKey({
source_nft_contract_address: sourceNft,
});
const dic_key = crypto.createHash("sha256").update(bytes).digest("hex");

const duplicate_storage_dict = await cep78Client.contractClient
const duplicate_storage_dict = await bc
.queryContractDictionary("duplicate_storage_dict", dic_key)
.catch(() => false)
.then(() => true);
if (duplicate_storage_dict) return true;

const original_storage_dict = await cep78Client.contractClient
const original_storage_dict = await bc
.queryContractDictionary("original_storage_dict", dic_key)
.catch(() => false)
.then(() => true);
Expand Down
8 changes: 3 additions & 5 deletions src/handlers/casper/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ export function Serializer() {
]);
},
storageKey(args: TStorageKeyArgs) {
const source_nft_contract_address = stringSerializer
.toBytes(new CLString(args.source_nft_contract_address))
.expect(
"Serialize(StorageKeyArgs): Failed to serialize source_nft_contract_address to bytes.",
);
const source_nft_contract_address = new Uint8Array(
Buffer.from(args.source_nft_contract_address, "hex"),
);

const self_chain = stringSerializer
.toBytes(new CLString("CASPER"))
Expand Down

0 comments on commit 128d38a

Please sign in to comment.