From 4d3affd429cbdad46e8ba3785d1c3e1be1746c9d Mon Sep 17 00:00:00 2001 From: Pierre Seznec Date: Thu, 19 Oct 2023 14:09:22 +0200 Subject: [PATCH] add website deployer for v26 --- smart-contracts/assembly/contracts/NFT/NFT.ts | 4 ++- .../website-deployer/websiteDeployer.ts | 5 +-- .../website-deployer/websiteDeployer_v26.ts | 34 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 smart-contracts/assembly/contracts/website-deployer/websiteDeployer_v26.ts diff --git a/smart-contracts/assembly/contracts/NFT/NFT.ts b/smart-contracts/assembly/contracts/NFT/NFT.ts index 5a42d4ba..eed76c44 100644 --- a/smart-contracts/assembly/contracts/NFT/NFT.ts +++ b/smart-contracts/assembly/contracts/NFT/NFT.ts @@ -98,12 +98,13 @@ export function constructor(binaryArgs: StaticArray): void { * @param binaryArgs - Serialized URI String with `Args` */ export function nft1_setURI(binaryArgs: StaticArray): void { + assert(_onlyOwner(), 'The caller is not the owner of the contract'); + const args = new Args(binaryArgs); const newBaseURI = args .nextString() .expect('BaseURI argument is missing or invalid'); - assert(_onlyOwner(), 'The caller is not the owner of the contract'); Storage.set(baseURIKey, newBaseURI); generateEvent(createEvent('baseURI', [newBaseURI])); } @@ -163,6 +164,7 @@ export function nft1_setTokenURI(binaryArgs: StaticArray): void { .expect('token id argument is missing or invalid'); assertIsMinted(tokenId); assertIsOwner(Context.caller().toString(), tokenId); + Storage.set( tokenURIKey + tokenId.toString(), args.nextString().expect('tokenURI argument is missing or invalid'), diff --git a/smart-contracts/assembly/contracts/website-deployer/websiteDeployer.ts b/smart-contracts/assembly/contracts/website-deployer/websiteDeployer.ts index be311bc3..8dc1dff9 100644 --- a/smart-contracts/assembly/contracts/website-deployer/websiteDeployer.ts +++ b/smart-contracts/assembly/contracts/website-deployer/websiteDeployer.ts @@ -7,6 +7,9 @@ import { Context, } from '@massalabs/massa-as-sdk'; +const StorageCostPerByte = 1_000_000; +const StorageKeyCreation = 10 * StorageCostPerByte; + /** * Creates a new smart contract with the websiteDeployer.wasm file content. * @@ -17,8 +20,6 @@ export function main(_: StaticArray): void { const websiteAddr = createSC(bytes); - const StorageCostPerByte = 1_000_000; - const StorageKeyCreation = 10 * StorageCostPerByte; // this will be updated when charging storage key for actual size // const StorageKeyCreation = stringToBytes(OWNER_KEY).length * StorageCostPerByte; diff --git a/smart-contracts/assembly/contracts/website-deployer/websiteDeployer_v26.ts b/smart-contracts/assembly/contracts/website-deployer/websiteDeployer_v26.ts new file mode 100644 index 00000000..0c0dfc2f --- /dev/null +++ b/smart-contracts/assembly/contracts/website-deployer/websiteDeployer_v26.ts @@ -0,0 +1,34 @@ +import { Args, stringToBytes } from '@massalabs/as-types'; +import { + createSC, + generateEvent, + fileToByteArray, + call, + Context, +} from '@massalabs/massa-as-sdk'; +import { OWNER_KEY } from '../utils/ownership-internal'; + +const baseCostBytes = 4; +const StorageCostPerByte = 100_000; + +/** + * Creates a new smart contract with the websiteDeployer.wasm file content. + * + * @param _ - not used + */ +export function main(_: StaticArray): void { + const bytes: StaticArray = fileToByteArray('./build/websiteStorer.wasm'); + + const websiteAddr = createSC(bytes); + + const StorageKeyLen = stringToBytes(OWNER_KEY).length; + const StorageValueLen = stringToBytes(Context.caller().toString()).length; + + // cost of storing owner key + const coins = + StorageCostPerByte * (baseCostBytes + StorageKeyLen + StorageValueLen); + + call(websiteAddr, 'constructor', new Args(), coins); + + generateEvent(`Contract deployed at address: ${websiteAddr.toString()}`); +}