Skip to content

Commit

Permalink
add MS deploySc
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Dec 2, 2024
1 parent 6e1ffb6 commit 16fba9f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions src/bearbyWallet/BearbyAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export class BearbyAccount implements Provider {
maxGas: params.maxGas || MAX_GAS_DEPLOYMENT,
coins: params.coins,
fee: fee,
gasPrice: 10000n,
contractDataBase64: uint8ArrayToBase64(params.byteCode),
deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),
};
Expand Down
34 changes: 24 additions & 10 deletions src/massaStation/MassaStationAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { argsToBase64, uint8ArrayToBase64 } from '../utils/argsToBase64';
import bs58check from 'bs58check';
import {
DeploySCFunctionBody,
ExecuteFunctionBody,
MSAccountSignPayload,
MSAccountSignResp,
Expand Down Expand Up @@ -34,6 +35,7 @@ import {
SCEvent,
SignedData,
SmartContract,
StorageCost,
strToBytes,
} from '@massalabs/massa-web3';
import { getClient, networkInfos } from './utils/network';
Expand Down Expand Up @@ -238,18 +240,30 @@ export class MassaStationAccount implements Provider {
}

public async deploySC(params: DeploySCParams): Promise<SmartContract> {
console.log(params);
// const body: DeploySCFunctionBody = {
// nickname: this.accountName,
// smartContract: params.byteCode
// };
const parameters = params.parameter as Uint8Array; // Args to based64 is not supported
const totalCost =
StorageCost.smartContract(params.byteCode.length) + params.coins;

// const res = await postRequest<MSSendOperationResp>(
// `${MASSA_STATION_URL}cmd/deploySC`,
// body,
// );
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())),
};

throw new Error('Method not implemented.');
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,
);

return new SmartContract(this, deployedAddress);
}

public async getOperationStatus(opId: string): Promise<OperationStatus> {
Expand Down
1 change: 0 additions & 1 deletion src/massaStation/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export async function postRequest<T>(
const resp = await axios.post<unknown, AxiosResponse, object>(url, body, {
headers: requestHeaders,
});

return { isError: false, result: resp.data };
} catch (error) {
return {
Expand Down
8 changes: 4 additions & 4 deletions src/massaStation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ export type ExecuteFunctionBody = {

export type DeploySCFunctionBody = {
nickname: string;
smartContract: File;
gasLimit: number;
smartContract: string;
maxCoins: number;
coins: number;
expiry: number;
parameters: string;
fee: number;
datastore: string;
};

export type PluginInfo = {
Expand Down Expand Up @@ -95,4 +94,5 @@ export type MSAccountSignResp = {

export type MSSendOperationResp = {
operationId: string;
events: any[];
};

0 comments on commit 16fba9f

Please sign in to comment.