Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Dec 2, 2024
1 parent 42afde1 commit 7e6cb70
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 51 deletions.
84 changes: 71 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
],
"dependencies": {
"@hicaru/bearby.js": "^0.5.9",
"@massalabs/massa-web3": "^5.0.1-dev",
"@massalabs/massa-web3": "^5.0.1-dev.20241128131418",
"axios": "^0.28.0",
"bs58check": "^4.0.0",
"buffer": "^6.0.3",
Expand Down
16 changes: 0 additions & 16 deletions src/bearbyWallet/BearbyAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import { operationType } from '../utils/constants';
import {
Address,
CallSCParams,
DEPLOYER_BYTECODE,
DeploySCParams,
EventFilter,
formatNodeStatusObject,
JsonRPCClient,
Mas,
MAX_GAS_CALL,
MAX_GAS_DEPLOYMENT,
MAX_GAS_DEPLOYMENT,
Network,
NodeStatusInfo,
Operation,
Expand All @@ -36,7 +34,6 @@ import { WalletName } from '../wallet';
import isEqual from 'lodash.isequal';
import { uint8ArrayToBase64 } from '../utils/argsToBase64';
import { DEPLOYER_BYTECODE } from '@massalabs/massa-web3/dist/esm/generated/deployer-bytecode';
import * as StorageCost from '@massalabs/massa-web3/dist/esm/basicElements/storage';

export class BearbyAccount implements Provider {
public constructor(public address: string) {}
Expand Down Expand Up @@ -255,7 +252,6 @@ export class BearbyAccount implements Provider {
const totalCost =
StorageCost.smartContract(params.byteCode.length) + params.coins;

<<<<<<< HEAD
const args = {
...params,
maxCoins: totalCost,
Expand All @@ -266,18 +262,6 @@ export class BearbyAccount implements Provider {
contractDataBase64: uint8ArrayToBase64(params.byteCode),
deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),
};
=======
const args = {
...params,
maxCoins: totalCost,
maxGas: params.maxGas || MAX_GAS_DEPLOYMENT,
coins: params.coins,
fee: fee,
gasPrice: 10000n,
contractDataBase64: uint8ArrayToBase64(params.byteCode),
deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),
};
>>>>>>> 16fba9f (add MS deploySc)

const operationId = await web3.contract.deploy(args);

Expand Down
50 changes: 29 additions & 21 deletions src/massaStation/MassaStationAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,30 +242,38 @@ export class MassaStationAccount implements Provider {
}

public async deploySC(params: DeploySCParams): Promise<SmartContract> {
const parameters = params.parameter as Uint8Array; // Args to based64 is not supported
const totalCost =
StorageCost.smartContract(params.byteCode.length) + params.coins;
try {
const args = params.parameter ?? new Uint8Array();
const parameters = args instanceof Uint8Array ? args : args.serialize();
const totalCost =
StorageCost.smartContract(params.byteCode.length) + params.coins;

const body: DeploySCFunctionBody = {
nickname: this.accountName,
smartContract: uint8ArrayToBase64(params.byteCode),
maxCoins: Number(totalCost),
coins: Number(params.coins), // SmartContract deployment costs
parameters: uint8ArrayToBase64(parameters),
fee: Number(params.fee || (await this.minimalFee())),
};

const res = await postRequest<MSSendOperationResp>(
`${MASSA_STATION_URL}cmd/deploySC`,
body,
);
const operationId = res.result?.operationId;

const body: DeploySCFunctionBody = {
nickname: this.accountName,
smartContract: uint8ArrayToBase64(params.byteCode),
maxCoins: Number(totalCost),
coins: Number(params.coins), // SmartContract deployment costs
parameters: uint8ArrayToBase64(parameters),
fee: Number(params.fee || (await this.minimalFee())),
};
if (!operationId) throw new Error('Operation ID not found');

const res = await postRequest<MSSendOperationResp>(
`${MASSA_STATION_URL}cmd/deploySC`,
body,
);
const operationId = res.result?.operationId;
const operation = new Operation(this, operationId);
const deployedAddress = await operation.getDeployedAddress(
params.waitFinalExecution,
);
const operation = new Operation(this, operationId);
const deployedAddress = await operation.getDeployedAddress(
params.waitFinalExecution,
);

return new SmartContract(this, deployedAddress);
return new SmartContract(this, deployedAddress);
} catch (error) {
throw new Error(`Error during smart contract deployment: ${error}`);
}
}

public async getOperationStatus(opId: string): Promise<OperationStatus> {
Expand Down

0 comments on commit 7e6cb70

Please sign in to comment.