-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
139 additions
and
116 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
packages/massa-web3/src/experimental/basicElements/bytecode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { BlockchainClient } from '../client' | ||
import { MAX_GAS_EXECUTE } from '../smartContract' | ||
import { ZERO } from '../utils' | ||
import { PrivateKey } from './keys' | ||
import { Operation } from './operation' | ||
import { | ||
OperationManager, | ||
ExecuteOperation, | ||
calculateExpirePeriod, | ||
OperationType, | ||
} from './operationManager' | ||
|
||
type ExecuteOption = { | ||
fee?: bigint | ||
periodToLive?: number | ||
maxCoins?: bigint | ||
maxGas?: bigint | ||
datastore?: Map<Uint8Array, Uint8Array> | ||
} | ||
|
||
/** | ||
* A class to compile and execute byte code. | ||
* | ||
* @remarks | ||
* The difference between byte code and a smart contract is that the byte code is the raw code that will be | ||
* executed on the blockchain, while a smart contract is the code that is already deployed on the blockchain. | ||
* The byte code is only ephemeral and will be executed only once. | ||
* A smart contract has an address and exposes functions that can be called multiple times. | ||
* | ||
*/ | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
function compile(_source: string): Promise<Uint8Array> { | ||
throw new Error('Not implemented') | ||
} | ||
|
||
/** | ||
* | ||
* Executes a byte code on the blockchain. | ||
* | ||
* @param client - The client to connect to the desired blockchain. | ||
* @param privateKey - The private key of the account that will execute the byte code. | ||
* @param byteCode - The byte code to execute. | ||
* @param opts - Optional execution details. | ||
* | ||
* @returns The operation. | ||
*/ | ||
export async function execute( | ||
client: BlockchainClient, | ||
privateKey: PrivateKey, | ||
byteCode: Uint8Array, | ||
opts: ExecuteOption | ||
): Promise<Operation> { | ||
const operation = new OperationManager(privateKey, client) | ||
const details: ExecuteOperation = { | ||
fee: opts?.fee ?? (await client.getMinimalFee()), | ||
expirePeriod: calculateExpirePeriod( | ||
await client.fetchPeriod(), | ||
opts?.periodToLive | ||
), | ||
type: OperationType.ExecuteSmartContractBytecode, | ||
maxCoins: opts?.maxCoins ?? BigInt(ZERO), | ||
// TODO: implement max gas | ||
maxGas: opts?.maxGas || MAX_GAS_EXECUTE, | ||
contractDataBinary: byteCode, | ||
datastore: opts.datastore, | ||
} | ||
|
||
return new Operation(client, await operation.send(details)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const FIRST = 0 | ||
export const ZERO = 0 | ||
export const ONE = 1 |
Oops, something went wrong.
d028274
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report for experimental massa-web3
Caution
Test run failed
Test suite run failed
Failed tests: 0/10. Failed suites: 4/7.
Report generated by π§ͺjest coverage report action from d028274