Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add website deployer for v26 #126

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion smart-contracts/assembly/contracts/NFT/NFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ export function constructor(binaryArgs: StaticArray<u8>): void {
* @param binaryArgs - Serialized URI String with `Args`
*/
export function nft1_setURI(binaryArgs: StaticArray<u8>): 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]));
}
Expand Down Expand Up @@ -163,6 +164,7 @@ export function nft1_setTokenURI(binaryArgs: StaticArray<u8>): 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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -17,8 +20,6 @@ export function main(_: StaticArray<u8>): 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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<u8>): void {
const bytes: StaticArray<u8> = 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()}`);
}
Loading