|
| 1 | +// A part of standard library for Tolk |
| 2 | +tolk 0.6 |
| 3 | + |
| 4 | +/** |
| 5 | + Gas and payment related primitives. |
| 6 | + */ |
| 7 | + |
| 8 | +/// Returns amount of gas (in gas units) consumed in current Computation Phase. |
| 9 | +fun getGasConsumedAtTheMoment(): int |
| 10 | + asm "GASCONSUMED"; |
| 11 | + |
| 12 | +/// This function is required to be called when you process an external message (from an outer world) |
| 13 | +/// and "accept" it to blockchain. |
| 14 | +/// Without calling this function, an external message would be discarded. |
| 15 | +/// As an effect, the current smart contract agrees to buy some gas to finish the current transaction. |
| 16 | +/// For more details, check [accept_message effects](https://ton.org/docs/#/smart-contracts/accept). |
| 17 | +fun acceptExternalMessage(): void |
| 18 | + asm "ACCEPT"; |
| 19 | + |
| 20 | +/// When processing an internal message, by default, the limit of gas consumption is determined by incoming message. |
| 21 | +/// Functions [setGasLimit] and [setGasLimitToMaximum] allow you to change this behavior. |
| 22 | +/// Sets current gas limit `gl` to its maximal allowed value `gm`, and resets the gas credit `gc` to zero, |
| 23 | +/// decreasing the value of `gr` by `gc` in the process. |
| 24 | +fun setGasLimitToMaximum(): void |
| 25 | + asm "ACCEPT"; |
| 26 | + |
| 27 | +/// When processing an internal message, by default, the limit of gas consumption is determined by incoming message. |
| 28 | +/// Functions [setGasLimit] and [setGasLimitToMaximum] allow you to change this behavior. |
| 29 | +/// Sets current gas limit `gl` to the minimum of limit and `gm`, and resets the gas credit `gc` to zero. |
| 30 | +/// If the gas consumed so far (including the present instruction) exceeds the resulting value of `gl`, |
| 31 | +/// an (unhandled) out of gas exception is thrown before setting new gas limits. |
| 32 | +fun setGasLimit(limit: int): void |
| 33 | + asm "SETGASLIMIT"; |
| 34 | + |
| 35 | +/// Calculates fee (amount in nanotoncoins to be paid) for a transaction which consumed [gasUsed] gas units. |
| 36 | +fun calculateGasFee(workchain: int, gasUsed: int): int |
| 37 | + asm(gasUsed workchain) "GETGASFEE"; |
| 38 | + |
| 39 | +/// Same as [calculateGasFee], but without flat price (you have supposed to read https://docs.ton.org/develop/howto/fees-low-level) |
| 40 | +fun calculateGasFeeWithoutFlatPrice(workchain: int, gasUsed: int): int |
| 41 | + asm(gasUsed workchain) "GETGASFEESIMPLE"; |
| 42 | + |
| 43 | +/// Calculates amount of nanotoncoins you should pay for storing a contract of provided size for [seconds]. |
| 44 | +/// [bits] and [cells] represent contract state (code + data). |
| 45 | +fun calculateStorageFee(workchain: int, seconds: int, bits: int, cells: int): int |
| 46 | + asm(cells bits seconds workchain) "GETSTORAGEFEE"; |
| 47 | + |
| 48 | +/// Calculates amount of nanotoncoins you should pay to send a message of specified size. |
| 49 | +fun calculateMessageFee(workchain: int, bits: int, cells: int): int |
| 50 | + asm(cells bits workchain) "GETFORWARDFEE"; |
| 51 | + |
| 52 | +/// Same as [calculateMessageFee], but without lump price (you have supposed to read https://docs.ton.org/develop/howto/fees-low-level) |
| 53 | +fun calculateMessageFeeWithoutLumpPrice(workchain: int, bits: int, cells: int): int |
| 54 | + asm(cells bits workchain) "GETFORWARDFEESIMPLE"; |
| 55 | + |
| 56 | +/// Calculates fee that was paid by the sender of an incoming internal message. |
| 57 | +fun calculateOriginalMessageFee(workchain: int, incomingFwdFee: int): int |
| 58 | + asm(incomingFwdFee workchain) "GETORIGINALFWDFEE"; |
| 59 | + |
| 60 | +/// Returns the amount of nanotoncoins current contract debts for storage. ("due" and "debt" are synonyms) |
| 61 | +/// If it has no debt, `0` is returned. |
| 62 | +fun getMyStorageDuePayment(): int |
| 63 | + asm "DUEPAYMENT"; |
0 commit comments