Skip to content

Commit

Permalink
fix: recover account for getting upgraded cairo 1 address
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyyconsensys committed Nov 21, 2023
1 parent ef4eb37 commit bd45f53
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/starknet-snap/src/utils/starknetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ export const getCorrectContractAddress = async (network: Network, publicKey: str
logger.log(
`getContractAddressByKey: contractAddressCario1 = ${contractAddress}\ncontractAddressCairo0 = ${contractAddressCairo0}\npublicKey = ${publicKey}`,
);

//test if it is a cairo 1 account
try {
pk = await getOwner(contractAddress, network);
logger.log(`getContractAddressByKey: cairo 1 contract found`);
Expand All @@ -631,6 +633,23 @@ export const getCorrectContractAddress = async (network: Network, publicKey: str
throw err;
}
logger.log(`getContractAddressByKey: cairo 1 contract not found`);

//test if it is a upgraded cairo 0 account
try {
pk = await getOwner(contractAddressCairo0, network);
logger.log(`getContractAddressByKey: upgraded cairo 0 contract found`);
return {
address: contractAddressCairo0,
signerPubKey: pk,
};
} catch (err) {
if (!err.message.includes('Contract not found')) {
throw err;
}
logger.log(`getContractAddressByKey: upgraded cairo 0 contract not found`);
}

//test if it is a deployed cairo 0 account
try {
pk = await getSigner(contractAddressCairo0, network);
logger.log(`getContractAddressByKey: cairo 0 contract found`);
Expand All @@ -645,6 +664,8 @@ export const getCorrectContractAddress = async (network: Network, publicKey: str
logger.log(`getContractAddressByKey: cairo 0 contract not found`);
}
}

//return new/deployed cairo 1 account
return {
address: contractAddress,
signerPubKey: pk,
Expand Down

0 comments on commit bd45f53

Please sign in to comment.