You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**program.json** is the Leo manifest file that configures our package.
11
11
```json title="program.json"
@@ -26,12 +26,109 @@ The program ID in `program` is the official name that other developers will be a
26
26
27
27
Dependencies will be added to the field of the same name, as they are added. The dependencies are also pegged in the **leo.lock** file.
28
28
29
-
## The Code
30
29
31
-
The `src/` directory is where all of your Leo code will live. The main entry point of your project is a file in this directory.appropriately named `main.leo`. Calls to many of the Leo CLI commands will require you to have this file within your project in order to succeed properly.
30
+
The `src/` directory is where all of your Leo code will live. The main entry point of your project is a file in this directoryappropriately named `main.leo`. Calls to many of the Leo CLI commands will require you to have this file within your project in order to succeed properly.
32
31
33
32
34
-
### Modules
33
+
## Programs
34
+
35
+
A program is a collection of code (its functions) and data (its types) that resides at a
36
+
[program ID](#program-id) on the Aleo blockchain. A program is declared as `program {name}.{network} { ... }`.
37
+
The body of the program is delimited by curly braces `{}`.
38
+
39
+
```leo title=main.leo
40
+
import foo.aleo;
41
+
42
+
program hello.aleo {
43
+
const FOO: u64 = 1u64;
44
+
mapping account: address => u64;
45
+
46
+
record Token {
47
+
owner: address,
48
+
amount: u64,
49
+
}
50
+
51
+
struct Message {
52
+
sender: address,
53
+
object: u64,
54
+
}
55
+
56
+
async transition mint_public(
57
+
public receiver: address,
58
+
public amount: u64,
59
+
) -> (Token, Future) {
60
+
return (Token {
61
+
owner: receiver,
62
+
amount,
63
+
}, update_state(receiver, amount));
64
+
}
65
+
66
+
async function update_state(
67
+
public receiver: address,
68
+
public amount: u64,
69
+
) {
70
+
let current_amount: u64 = Mapping::get_or_use(account, receiver, 0u64);
Leo supports tuples. Tuple types are declared as `(type1, type2, ...)` and can be nested. Tuples cannot be empty or modified.
185
187
@@ -232,8 +234,25 @@ let m = Matrix::[2, 2] { data: [0, 1, 2, 3] };
232
234
```
233
235
Note that generic structs cannot currently be imported outside a program, but can be declared and used in submodules. Acceptable types for const generic parameters include integer types, `bool`, `scalar`, `group`, `field`, and `address`.
234
236
237
+
### Records
238
+
239
+
A [record](https://developer.aleo.org/concepts/fundamentals/records) data type is the method of encoding private state on Aleo. Records are declared as `record {name} {}`. A record name must not contain the keyword `aleo`, and must not be a prefix of any other record name.
240
+
241
+
Records contain component declarations `{visibility} {name}: {type},`. Names of record components must not contain the keyword `aleo`. The visibility qualifier may be specified as `constant`, `public`, or `private`. If no qualifier is provided, Leo defaults to `private`.
242
+
243
+
Record data structures must always contain a component named `owner` of type `address`, as shown below. When passing a record as input to a program function, the `_nonce: group` and `_version: u8` components are also required but do not need to be declared in the Leo program. They are inserted automatically by the compiler.
244
+
245
+
```aleo showLineNumbers
246
+
record Token {
247
+
// The token owner.
248
+
owner: address,
249
+
// The token amount.
250
+
amount: u64,
251
+
}
252
+
```
253
+
235
254
## Option Types
236
-
As of v3.3.0, Leo supports first-class option types using the `T?` syntax, where `T` is any of the types previously mentioned, excluding `address`, `signature`, and `tuple`. A value of type `T?` can be initialized into two states: either a value of type `T`, or `none`:
255
+
As of v3.3.0, Leo supports first-class option types using the `T?` syntax, where `T` is any of the types previously mentioned, excluding `record`, `address`, `signature`, and `tuple`. A value of type `T?` can be initialized into two states: either a value of type `T`, or `none`:
0 commit comments