Skip to content
Open
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
8 changes: 8 additions & 0 deletions smart-contract/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module.exports = {
extends: ['@massalabs'],
overrides: [
{
files: ['src/**/*.ts'],
rules: {
'no-console': 'off',
},
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,3 @@ export function _assertHasNoChunk(locationHash: StaticArray<u8>): void {
export function _assertHasNoCoins(): void {
assert(balance() === 0, 'Balance should be zero');
}

16 changes: 10 additions & 6 deletions smart-contract/assembly/contracts/deweb-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ export function setMetadataFile(_binaryArgs: StaticArray<u8>): void {
.next<StaticArray<u8>>()
.expect('Invalid hashLocation');

assert(hashLocation.length == 32, 'Invalid filpath sha256 hash. should be 32 bytes');
assert(
hashLocation.length == 32,
'Invalid filpath sha256 hash. should be 32 bytes',
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message contains a spelling mistake ('filpath' should be 'filepath'). Correcting this will improve clarity.

Suggested change
'Invalid filpath sha256 hash. should be 32 bytes',
'Invalid filepath sha256 hash. should be 32 bytes',

Copilot uses AI. Check for mistakes.
);

const metadata = args
.nextSerializableObjectArray<Metadata>()
Expand Down Expand Up @@ -262,7 +265,10 @@ export function removeMetadataFile(_binaryArgs: StaticArray<u8>): void {
.next<StaticArray<u8>>()
.expect('Invalid hashLocation');

assert(hashLocation.length == 32, 'Invalid filpath sha256 hash. should be 32 bytes');
assert(
hashLocation.length == 32,
'Invalid filpath sha256 hash. should be 32 bytes',
Copy link

Copilot AI Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message contains a typo ('filpath' should be 'filepath'). A correction here will enhance readability.

Suggested change
'Invalid filpath sha256 hash. should be 32 bytes',
'Invalid filepath sha256 hash. should be 32 bytes',

Copilot uses AI. Check for mistakes.
);

const metadata = args.next<string[]>().expect('Invalid key');

Expand Down Expand Up @@ -311,23 +317,21 @@ export function receiveCoins(): void {
export function upgradeSC(args: StaticArray<u8>): void {
_onlyOwner();
setBytecode(args);

// Send the freed coins back to the caller
transferCoins(Context.caller(), balance());
}


/* -------------------------------------------------------------------------- */
/* PURGE SC */
/* -------------------------------------------------------------------------- */

/**
* Deletes all the contract storage and bytecode.
* Sends back the freed coins to the caller.
* @param args - Ignored.
* @throws If the caller is not the owner.
*/
export function purge(args: StaticArray<u8>): void {
export function purge(_: StaticArray<u8>): void {
_onlyOwner();

// Delete all datastore entries
Expand Down
1 change: 1 addition & 0 deletions smart-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "massa-as-compile",
"clean": "rimraf build",
"deploy": "npm run build && tsx src/deploy.ts",
"upgrade": "npm run build && tsx src/upgrade.ts",
"prettier": "prettier '**/src/**/*.ts' --check && as-prettier --check assembly",
"prettier:fix": "prettier '**/src/**/*.ts' --write && as-prettier --write assembly",
"lint": "eslint .",
Expand Down
10 changes: 2 additions & 8 deletions smart-contract/src/e2e/helpers/serializable/Metadata.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { Args, DeserializedResult, Serializable } from '@massalabs/massa-web3';

export class Metadata implements Serializable<Metadata> {
constructor(
public key: string = '',
public value: string = '',
) {}
constructor(public key: string = '', public value: string = '') {}

serialize(): Uint8Array {
return new Args()
.addString(this.key)
.addString(this.value)
.serialize();
return new Args().addString(this.key).addString(this.value).serialize();
}

deserialize(data: Uint8Array, offset: number): DeserializedResult<Metadata> {
Expand Down
25 changes: 25 additions & 0 deletions smart-contract/src/upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
Account,
Mas,
SmartContract,
Web3Provider,
} from '@massalabs/massa-web3';
import { getByteCode } from './utils';

const CONTRACT_ADDR = 'AS1BsB34Hq7VGpGG26cudgFr15nshSeJfAkkf6WGY8JcXbG6kzUg';

const account = await Account.fromEnv();
const provider = Web3Provider.mainnet(account);
const contract = new SmartContract(provider, CONTRACT_ADDR);

const byteCode = getByteCode('build', 'deweb-interface.wasm');

const operation = await contract.call('upgradeSC', byteCode, {
coins: Mas.fromString('3'),
fee: Mas.fromString('0.1'),
});

const events = await operation.getSpeculativeEvents();
for (const event of events) {
console.log('upgradeSC Events:', event.data);
}