diff --git a/smart-contract/.nvmrc b/smart-contract/.nvmrc new file mode 100644 index 0000000..209e3ef --- /dev/null +++ b/smart-contract/.nvmrc @@ -0,0 +1 @@ +20 diff --git a/smart-contract/src/infos.ts b/smart-contract/src/infos.ts index 32f41de..14583ce 100644 --- a/smart-contract/src/infos.ts +++ b/smart-contract/src/infos.ts @@ -1,5 +1,6 @@ import { getDomains, + getDomainsFromTarget, getOwner, getTokenCounter, getTotalSupply, @@ -24,3 +25,8 @@ try { } catch (e) { console.log('No total supply found'); } + +// reverse resolve +const target = 'AS1ZTEiyBCyVAdpMfdU7br3xxPSj99kNZTxVXhnuYH7DkDF6h9YK'; +const revRes = await getDomainsFromTarget(provider, target); +console.log('target domains:', revRes); diff --git a/smart-contract/src/migrate.ts b/smart-contract/src/migrate.ts index 80ca083..240a6be 100644 --- a/smart-contract/src/migrate.ts +++ b/smart-contract/src/migrate.ts @@ -1,15 +1,16 @@ -import { SmartContract, Mas, Operation, rpcTypes } from '@massalabs/massa-web3'; import { - getMigrateCounter, - getScByteCode, - getTokenCounter, - initProvider, -} from './utils'; + SmartContract, + Mas, + Operation, + rpcTypes, + Args, +} from '@massalabs/massa-web3'; +import { getScByteCode, initProvider } from './utils'; import { MNS_CONTRACT } from './config'; const provider = await initProvider(); -const byteCode = getScByteCode('build', 'main_mig.wasm'); +const byteCode = getScByteCode('build', 'main_prev.wasm'); const contract = new SmartContract(provider, MNS_CONTRACT); console.log( @@ -19,6 +20,7 @@ console.log( let op: Operation; let events: rpcTypes.OutputEvents; + op = await contract.call('upgradeSC', byteCode, { coins: Mas.fromString('3'), fee: Mas.fromString('0.1'), @@ -30,18 +32,22 @@ for (const event of events) { } console.log('upgradeSC done ! operation:', op.id); -const counter = await getTokenCounter(provider, MNS_CONTRACT); -let migrateCount = 0n; -try { - migrateCount = await getMigrateCounter(provider, MNS_CONTRACT); -} catch (e) { - console.log('no migrate counter found'); +console.log('Initialize migration'); + +op = await contract.call('initMig', byteCode, { + fee: Mas.fromString('0.1'), +}); +events = await op.getFinalEvents(); + +for (const event of events) { + console.log('upgradeSC Events:', event.data); } +console.log('Initialize done ! operation:', op.id); -while (migrateCount < counter) { - console.log('migrating batch from tokenID', migrateCount.toString()); - op = await contract.call('migrate', undefined, { - coins: Mas.fromString('30'), +let batchSize = 3000; +while (true) { + op = await contract.call('migrate', new Args().addI32(BigInt(batchSize)), { + coins: Mas.fromString('25'), fee: Mas.fromString('0.1'), }); @@ -50,24 +56,11 @@ while (migrateCount < counter) { for (const event of events) { console.log('migrate Events:', event.data); } - migrateCount = await getMigrateCounter(provider, MNS_CONTRACT); - console.log('new migrate count:', migrateCount.toString()); -} - -console.log('Upgrade done ! operation:'); - -if (migrateCount === counter) { - const cleaned = getScByteCode('build', 'main.wasm'); - - op = await contract.call('upgradeSC', cleaned, { - fee: Mas.fromString('0.1'), - }); - events = await op.getFinalEvents(); - for (const event of events) { - console.log('upgradeSC Events:', event.data); + if (events.some((event) => event.data.includes('Migration done'))) { + console.log('Migration done ! yallahh:'); + break; } - console.log('upgradeSC done ! operation:', op.id); } console.log( diff --git a/smart-contract/src/utils.ts b/smart-contract/src/utils.ts index f321654..3235a47 100644 --- a/smart-contract/src/utils.ts +++ b/smart-contract/src/utils.ts @@ -6,6 +6,7 @@ import { bytesToStr, Provider, SmartContract, + strToBytes, U256, Web3Provider, } from '@massalabs/massa-web3'; @@ -72,3 +73,19 @@ export async function getOwner(provider: Provider): Promise { const { value } = await contract.read('ownerAddress'); return bytesToStr(value); } + +export async function getDomainsFromTarget( + provider: Provider, + target: string, +): Promise { + const ADDRESS_KEY_PREFIX_V2 = [0x6]; + const targetBytes = strToBytes(target); + const prefix = Uint8Array.from([ + ...DOMAIN_SEPARATOR_KEY, + ...ADDRESS_KEY_PREFIX_V2, + targetBytes.length, + ...targetBytes, + ]); + const keys = await provider.getStorageKeys(MNS_CONTRACT, prefix); + return keys.map((key) => bytesToStr(key.slice(prefix.length))); +}