File Structure

The structure of a btm file is the following:

  • package declaration (optional)
  • network declaration (optional)
  • constants and transactions declaration
  • compile statement (optional)

Package

The package declaration specify where the generated files must be saved. By default, generated files are saved in src-gen with a directory structure reflecting the package name. For example, declaring package com.example.test, the generated files will be store in src-gen/com/example/test/.

package com.example.test

The package declaration is optional, but recommended, and must appear at the beginning of the file. The name of the package follows the same rules and conventions of Java packages.

Network

Several static checks depend on the network you are considering. The Wallet Import Format [1], used to represent private keys and addresses, include a network identifier which made it wrong outside that network. Furthermore, since we are generating transactions, the network declaration is needed for serialization.

The network declaration is optional. If omitted, the testnet network is considered by default. If specified, the network declaration must appear right after the package declaration.

package com.example.test

// <-- you can put comments here

network testnet
package com.example.test

/* <-- you can put multi-line comments here */

network mainnet

Constants

Constants are immutable global variables. The syntax is const __name__ [: __type__] = __expression__. For example:

const n = 42
const n:int = 42

The type can be omitted, because it is inferred by the expression. Refer to Types and Expressions for details.

Transactions

See Transactions.

Tip

Constant and transaction declarations can be mixed together.

It is allowed to write:

const n = 42

transaction T { /* ... */ }

const s = "Hello world"

Tip

Cross-references are resolved independently from the declaration order, so it is allowed to write:

const n = 21 * m
const m = 2

Compile

The compile statement takes a list of expression and compile them. The compiled expressions are saved in text format in src-gen/_package-path_/transactions.

transaction T { /* ... */ }
transaction T1(a:int) { /* ... */ }
const n = 11

compile
        32          // compiles 32
        T           // compiles T as a bitcoin transaction
        T1(42)      // compiles T1(42) as a bitcoin transaction
        (n + 5)     // compiles 16

References

[1]https://bitcoin.org/en/glossary/wallet-import-format