Skip to content

Commit

Permalink
Smart contract panic
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-face committed Aug 5, 2024
1 parent 2b02aea commit a12fb49
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 64 deletions.
2 changes: 2 additions & 0 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ async function run() {
.description("Upload data to SocialDB from bos.config.json configuration")
.argument("[appName]", "Workspace app name to deploy")
.option("-n, --network <network>", "network to deploy to", "mainnet")
.option("--signerPublicKey <string>", "Signer public key")
.option("--signerPrivateKey <string>", "Signer private key")
.action(async (appName, options) => {
const deployOptions: DeployOptions = {
signerPublicKey: options.signerPublicKey,
Expand Down
142 changes: 78 additions & 64 deletions lib/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,32 @@ export async function deployAppData(appName: string, opts: DeployOptions) {
});
}

export async function deployAppDataFolders(appName: string, opts: DeployOptions) {
const config = await readConfig(path.join(appName, "bos.config.json"), opts.network);
const BOS_SIGNER_ACCOUNT_ID = config.accounts.signer || opts.signerAccountId || config.account;
export async function deployAppDataFolders(
appName: string,
opts: DeployOptions
) {
const config = await readConfig(
path.join(appName, "bos.config.json"),
opts.network
);
const BOS_SIGNER_ACCOUNT_ID =
config.accounts.signer || opts.signerAccountId || config.account;

if (!BOS_SIGNER_ACCOUNT_ID) {
console.log(`App account is not defined for ${appName}. Skipping data upload`);
console.log(
`App account is not defined for ${appName}. Skipping data upload`
);
return;
}

if (!config.data || !Array.isArray(config.data.include) || config.data.include.length === 0) throw new Error('Config must contain a data.include array with at least one folder');
if (
!config.data ||
!Array.isArray(config.data.include) ||
config.data.include.length === 0
)
throw new Error(
"Config must contain a data.include array with at least one folder"
);

const result = {};

Expand All @@ -197,68 +213,66 @@ export async function deployAppDataFolders(appName: string, opts: DeployOptions)
}
}

const outputPath = path.join(process.cwd(), 'combined_output.json');
await fs.writeFileSync(outputPath, JSON.stringify(result, null, 2));
const args = {
data: {
[config.account]: result,
},
};

const argsBase64 = Buffer.from(JSON.stringify(args)).toString("base64");

let command = [
"near-cli-rs",
"contract",
"call-function",
"as-transaction",
opts.network === "mainnet"
? SOCIAL_CONTRACT.mainnet
: SOCIAL_CONTRACT.testnet,
"set",
"base64-args",
`${argsBase64}`,
"prepaid-gas",
"300 TeraGas",
"attached-deposit",
"0.15 NEAR", // deposit
"sign-as",
BOS_SIGNER_ACCOUNT_ID,
"network-config",
opts.network,
];

const BOS_SIGNER_PUBLIC_KEY = opts?.signerPublicKey;
const BOS_SIGNER_PRIVATE_KEY = opts?.signerPrivateKey;

const automaticSignIn = [
"sign-with-plaintext-private-key",
"--signer-public-key",
BOS_SIGNER_PUBLIC_KEY,
"--signer-private-key",
BOS_SIGNER_PRIVATE_KEY,
"send",
];

console.log(`Combined JSON written to ${outputPath}`);
if (BOS_SIGNER_PUBLIC_KEY && BOS_SIGNER_PRIVATE_KEY)
command = command.concat(automaticSignIn);

// const dataJSON = fs.readFileSync(
// path.join(appName, DEPLOY_DIST_FOLDER, "data.json"),
// "utf8"
// );
const deployProcess = spawn("npx", command, {
cwd: path.join(appName, DEPLOY_DIST_FOLDER),
stdio: "inherit",
});

// const args = { data: JSON.parse(dataJSON) };
// const argsBase64 = Buffer.from(JSON.stringify(args)).toString("base64");

// const BOS_SIGNER_PUBLIC_KEY = opts?.signerPublicKey;
// const BOS_SIGNER_PRIVATE_KEY = opts?.signerPrivateKey;

// const automaticSignIn = [
// "sign-with-plaintext-private-key",
// "--signer-public-key",
// BOS_SIGNER_PUBLIC_KEY,
// "--signer-private-key",
// BOS_SIGNER_PRIVATE_KEY,
// "send"
// ]

// let command = [
// "near-cli-rs",
// "contract",
// "call-function",
// "as-transaction",
// opts.network === "mainnet" ? SOCIAL_CONTRACT.mainnet : SOCIAL_CONTRACT.testnet,
// "set",
// "base64-args",
// `${argsBase64}`,
// "prepaid-gas",
// "300 TeraGas",
// "attached-deposit",
// "0.15 NEAR", // deposit
// "sign-as",
// BOS_SIGNER_ACCOUNT_ID,
// "network-config",
// opts.network,
// ];

// if (BOS_SIGNER_PUBLIC_KEY && BOS_SIGNER_PRIVATE_KEY) command = command.concat(automaticSignIn)

// const deployProcess = spawn("npx", command, {
// cwd: path.join(appName, DEPLOY_DIST_FOLDER),
// stdio: "inherit",
// });

// deployProcess.on("close", (code) => {
// if (code === 0) {
// console.log(`Uploaded data for ${appName}`);
// } else {
// console.error(`Data upload failed with code ${code}`);
// }
// });

// deployProcess.on("error", (err) => {
// console.error(`Error uploading data for ${appName}:\n${err.message}`);
// });
deployProcess.on("close", (code) => {
if (code === 0) {
console.log(`Uploaded data for ${appName}`);
} else {
console.error(`Data upload failed with code ${code}`);
}
});

deployProcess.on("error", (err) => {
console.error(`Error uploading data for ${appName}:\n${err.message}`);
});
}

export async function deploy(appName: string, opts: DeployOptions) {
Expand Down

0 comments on commit a12fb49

Please sign in to comment.