-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from ton-org/tolk-integration
Support for Tolk Language: next-generation FunC
- Loading branch information
Showing
20 changed files
with
489 additions
and
37 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{name}}.compile.ts | ||
import { CompilerConfig } from '@ton/blueprint'; | ||
|
||
export const compile: CompilerConfig = { | ||
lang: 'tolk', | ||
entrypoint: '{{contractPath}}', | ||
withStackComments: true, // Fift output will contain comments, if you wish to debug its output | ||
experimentalOptions: '', // you can pass experimental compiler options here | ||
}; |
71 changes: 71 additions & 0 deletions
71
src/templates/tolk/counter/contracts/contract.tolk.template
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,71 @@ | ||
{{snakeName}}.tolk | ||
// simple counter contract in Tolk language | ||
|
||
const OP_INCREASE = 0x7e8764ef; // arbitrary 32-bit number, equal to OP_INCREASE in wrappers/CounterContract.ts | ||
|
||
// storage variables | ||
|
||
// id is required to be able to create different instances of counters | ||
// since addresses in TON depend on the initial state of the contract | ||
global ctxID: int; | ||
global ctxCounter: int; | ||
|
||
// loadData populates storage variables from persistent storage | ||
fun loadData() { | ||
var ds = getContractData().beginParse(); | ||
|
||
ctxID = ds.loadUint(32); | ||
ctxCounter = ds.loadUint(32); | ||
|
||
ds.assertEndOfSlice(); | ||
} | ||
|
||
// saveData stores storage variables as a cell into persistent storage | ||
fun saveData() { | ||
setContractData( | ||
beginCell() | ||
.storeUint(ctxID, 32) | ||
.storeUint(ctxCounter, 32) | ||
.endCell() | ||
); | ||
} | ||
|
||
// onInternalMessage is the main entrypoint; it's called when a contract receives an internal message from other contracts | ||
fun onInternalMessage(myBalance: int, msgValue: int, msgFull: cell, msgBody: slice) { | ||
if (msgBody.isEndOfSlice()) { // ignore all empty messages | ||
return; | ||
} | ||
|
||
var cs: slice = msgFull.beginParse(); | ||
val flags = cs.loadMessageFlags(); | ||
if (isMessageBounced(flags)) { // ignore all bounced messages | ||
return; | ||
} | ||
|
||
loadData(); // here we populate the storage variables | ||
|
||
val op = msgBody.loadMessageOp(); // by convention, the first 32 bits of incoming message is the op | ||
val queryID = msgBody.loadMessageQueryId(); // also by convention, the next 64 bits contain the "query id", although this is not always the case | ||
|
||
if (op == OP_INCREASE) { | ||
val increaseBy = msgBody.loadUint(32); | ||
ctxCounter += increaseBy; | ||
saveData(); | ||
return; | ||
} | ||
|
||
throw 0xffff; // if the message contains an op that is not known to this contract, we throw | ||
} | ||
|
||
// get methods are a means to conveniently read contract data using, for example, HTTP APIs | ||
// note that unlike in many other smart contract VMs, get methods cannot be called by other contracts | ||
|
||
get currentCounter(): int { | ||
loadData(); | ||
return ctxCounter; | ||
} | ||
|
||
get initialId(): int { | ||
loadData(); | ||
return ctxID; | ||
} |
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,22 @@ | ||
deploy{{name}}.ts | ||
import { toNano } from '@ton/core'; | ||
import { {{name}} } from '../wrappers/{{name}}'; | ||
import { compile, NetworkProvider } from '@ton/blueprint'; | ||
|
||
export async function run(provider: NetworkProvider) { | ||
const {{loweredName}} = provider.open( | ||
{{name}}.createFromConfig( | ||
{ | ||
id: Math.floor(Math.random() * 10000), | ||
counter: 0, | ||
}, | ||
await compile('{{name}}') | ||
) | ||
); | ||
|
||
await {{loweredName}}.sendDeploy(provider.sender(), toNano('0.05')); | ||
|
||
await provider.waitForDeploy({{loweredName}}.address); | ||
|
||
console.log('ID', await {{loweredName}}.getID()); | ||
} |
Oops, something went wrong.