Skip to content

Commit

Permalink
wip: add implementation working for predicate deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio committed Oct 6, 2024
1 parent eea9c8c commit 60b62ee
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
27 changes: 17 additions & 10 deletions packages/contract/src/contract-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
BlobTransactionRequest,
TransactionStatus,
calculateGasFee,
getPredicateRoot,
} from '@fuel-ts/account';
import { randomBytes } from '@fuel-ts/crypto';
import { ErrorCode, FuelError } from '@fuel-ts/errors';
Expand Down Expand Up @@ -388,17 +389,20 @@ export default class ContractFactory {
loaderBytecode: Uint8Array;
loaderBytecodeHexlified: string;
}> {
/** TODO: Implement me */
// @ts-expect-error lol
const {
waitForResult,
blobId,
loaderBytecode,
loaderBytecodeHexlified,
} = await this.deployAsBlobTxForScript(configurableConstants);

return Promise.resolve({
waitForResult: () =>
Promise.resolve({
transactionResult: {},
loaderBytecode: '',
}),
predicateRoot: '',
loaderBytecode: new Uint8Array(),
loaderBytecodeHexlified: '',
blobId,
waitForResult,
predicateRoot: getPredicateRoot(loaderBytecode),
loaderBytecode,
loaderBytecodeHexlified,
offset: 0, // TODO: Implement me
});
}

Expand Down Expand Up @@ -428,6 +432,7 @@ export default class ContractFactory {
arrayify(this.bytecode),
arrayify(blobId)
);
console.dir(loaderBytecode, { depth: null });

// Check the account can afford to deploy all chunks and loader
let totalCost = bn(0);
Expand Down Expand Up @@ -457,6 +462,8 @@ export default class ContractFactory {
let result: TransactionResult<TransactionType.Blob>;

try {
// TODO: MAKE SURE WE QUERY THE BLOB TO SEE IF EXISTS
// query { blobExits(0x000000000000) }
const blobTx = await account.sendTransaction(fundedBlobRequest);
result = await blobTx.waitForResult();
} catch (err: unknown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function getPredicateScriptLoaderInstructions(
dataView.setBigUint64(0, BigInt(dataSection.length), false); // false for big-endian

// Combine the instruction bytes, blob bytes, data section length, and the data section
return new Uint8Array([...instructionBytes, ...blobBytes]);
return new Uint8Array([...instructionBytes, ...blobBytes, ...dataSectionLenBytes, ...dataSection]);
}
// Handle case where there is no data section
const numOfInstructions = getInstructionsNoDataSection(0).length;
Expand Down
25 changes: 14 additions & 11 deletions packages/fuels/src/cli/commands/deploy/deployPredicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { readFileSync } from 'fs';
import {
getABIPath,
getBinaryPath,
getContractName,
getPredicateName,
} from '../../config/forcUtils';
import type { DeployedPredicate, FuelsConfig } from '../../types';
Expand All @@ -28,16 +27,20 @@ export async function deployPredicate(
const abi = JSON.parse(readFileSync(abiPath, 'utf-8'));
const factory = new ContractFactory(bytecode, abi, wallet);

const { waitForResult, predicateRoot, loaderBytecode, loaderBytecodeHexlified } =
await factory.deployAsBlobTxForPredicate(configurableConstants);
try {
const { predicateRoot, loaderBytecode, loaderBytecodeHexlified } =
await factory.deployAsBlobTxForPredicate(configurableConstants);
// await waitForResult();

await waitForResult();

return {
predicateRoot,
loaderBytecode,
loaderBytecodeHexlified,
};
return {
predicateRoot,
loaderBytecode,
loaderBytecodeHexlified,
};
} catch (err) {
console.error(err);
throw err;
}
}

/**
Expand All @@ -50,7 +53,7 @@ export async function deployPredicates(config: FuelsConfig) {

log(`Deploying predicates to: ${wallet.provider.url}`);

const predicatesLen = config.scripts.length;
const predicatesLen = config.predicates.length;

for (let i = 0; i < predicatesLen; i++) {
const predicatePath = config.predicates[i];
Expand Down
1 change: 1 addition & 0 deletions packages/fuels/src/cli/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function deploy(config: FuelsConfig) {
/**
* Deploy predicates and save deployed files to disk.
*/
console.log('config', config);
const predicates = await deployPredicates(config);
savePredicateFiles(predicates, config);

Expand Down

0 comments on commit 60b62ee

Please sign in to comment.