Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Willz450 committed Aug 24, 2024
1 parent 434e220 commit e4e2d88
Show file tree
Hide file tree
Showing 23 changed files with 341 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/helloworld/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NETWORK=testnet
PRIVATE_KEY=APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH
ENDPOINT=https://localhost:3030
PRIVATE_KEY=APrivateKey1zkp2YqKdKqTAzfCTwfQ9HVzApCmumRQfdKQdihMnGbn6856
ENDPOINT=https://api.explorer.aleo.org/v1
2 changes: 1 addition & 1 deletion examples/simple_token/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ program simple_token.aleo {
// The token owner.
owner: address,
// The token amount.
amount: u64,
amount: u64,mint
}

// The `mint` function initializes a new record with the
Expand Down
5 changes: 5 additions & 0 deletions examples/uduak_token1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
*.avm
*.prover
*.verifier
outputs/
13 changes: 13 additions & 0 deletions examples/uduak_token1/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# uduak_token1.aleo

## Build Guide

To compile this Aleo program, run:
```bash
snarkvm build
```

To execute this Aleo program, run:
```bash
snarkvm run hello
```
23 changes: 23 additions & 0 deletions examples/uduak_token1/build/main.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
program uduak_token1.aleo;

record Token:
owner as address.private;
amount as u64.private;


function mint:
input r0 as address.private;
input r1 as u64.private;
cast r0 r1 into r2 as Token.record;
output r2 as Token.record;


function transfer:
input r0 as Token.record;
input r1 as address.private;
input r2 as u64.private;
sub r0.amount r2 into r3;
cast r0.owner r3 into r4 as Token.record;
cast r1 r2 into r5 as Token.record;
output r4 as Token.record;
output r5 as Token.record;
7 changes: 7 additions & 0 deletions examples/uduak_token1/build/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"program": "uduak_token1.aleo",
"version": "0.1.0",
"description": "",
"license": "MIT",
"dependencies": null
}
1 change: 1 addition & 0 deletions examples/uduak_token1/leo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package = []
7 changes: 7 additions & 0 deletions examples/uduak_token1/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"program": "uduak_token1.aleo",
"version": "0.1.0",
"description": "",
"license": "MIT",
"dependencies": null
}
46 changes: 46 additions & 0 deletions examples/uduak_token1/src/main.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This example demonstrates an example of a minting and transferring a token in Leo.
program uduak_token1.aleo {
// The `Token` record datatype.
record Token {
// The token owner.
owner: address,
// The token amount.
amount: u64,
}

// The `mint` function initializes a new record with the
// specified number of tokens assigned to the specified receiver.
transition mint(owner: address, amount: u64) -> Token {
return Token {
owner: owner,
amount: amount,
};
}

// The `transfer` function sends the specified number of tokens
// to the receiver from the provided token record.
transition transfer(token: Token, to: address, amount: u64) -> (Token, Token) {

// Checks the given token record has sufficient balance.
// This `sub` operation is safe, and the proof will fail
// if an overflow occurs.
// `difference` holds the change amount to be returned to sender.
let difference: u64 = token.amount - amount;

// Produce a token record with the change amount for the sender.
let remaining: Token = Token {
owner: token.owner,
amount: difference,
};

// Produce a token record for the specified receiver.
let transferred: Token = Token {
owner: to,
amount: amount,
};

// Output the sender's change record and the receiver's record.
return (remaining, transferred);
}
}

5 changes: 5 additions & 0 deletions examples/uduakobong_hello1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
*.avm
*.prover
*.verifier
outputs/
13 changes: 13 additions & 0 deletions examples/uduakobong_hello1/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# uduakobong_hello1.aleo

## Build Guide

To compile this Aleo program, run:
```bash
snarkvm build
```

To execute this Aleo program, run:
```bash
snarkvm run hello
```
9 changes: 9 additions & 0 deletions examples/uduakobong_hello1/build/main.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
program uduakobong_hello1.aleo;



function main:
input r0 as u32.public;
input r1 as u32.private;
add r0 r1 into r2;
output r2 as u32.private;
7 changes: 7 additions & 0 deletions examples/uduakobong_hello1/build/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"program": "uduakobong_hello1.aleo",
"version": "0.1.0",
"description": "",
"license": "MIT",
"dependencies": null
}
1 change: 1 addition & 0 deletions examples/uduakobong_hello1/leo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package = []
7 changes: 7 additions & 0 deletions examples/uduakobong_hello1/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"program": "uduakobong_hello1.aleo",
"version": "0.1.0",
"description": "",
"license": "MIT",
"dependencies": null
}
7 changes: 7 additions & 0 deletions examples/uduakobong_hello1/src/main.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// The 'uduakobong_hello1' program.
program uduakobong_hello1.aleo {
transition main(public a: u32, b: u32) -> u32 {
let c: u32 = a + b;
return c;
}
}
5 changes: 5 additions & 0 deletions examples/uduakobong_voice6/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
*.avm
*.prover
*.verifier
outputs/
13 changes: 13 additions & 0 deletions examples/uduakobong_voice6/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# uduakobong_voice6.aleo

## Build Guide

To compile this Aleo program, run:
```bash
snarkvm build
```

To execute this Aleo program, run:
```bash
snarkvm run hello
```
62 changes: 62 additions & 0 deletions examples/uduakobong_voice6/build/main.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
program uduakobong_voice6.aleo;

record Voice:
owner as address.private;
receiver as address.private;
msg as u128.private;
hash_msg as u128.private;

record CoBind:
owner as address.private;
hash_owner as field.private;
receiver as address.private;
bind_hash as field.private;

struct Messaging:
messenger as field;
total_messages as u64;


mapping voice_msg:
key as field.public;
value as Messaging.public;


function send_voice:
input r0 as address.private;
input r1 as address.private;
input r2 as u128.private;
input r3 as field.private;
hash.bhp256 r2 into r4 as u128;
is.eq self.caller r0 into r5;
assert.eq r5 true;
assert.neq self.caller r1;
hash.bhp256 r0 into r6 as field;
hash.bhp256 r1 into r7 as field;
add r6 r7 into r8;
cast r0 r1 r2 r4 into r9 as Voice.record;
async send_voice r0 r4 into r10;
output r9 as Voice.record;
output r10 as uduakobong_voice6.aleo/send_voice.future;

finalize send_voice:
input r0 as address.public;
input r1 as u128.public;
hash.bhp256 r0 into r2 as field;
cast r2 0u64 into r3 as Messaging;
get.or_use voice_msg[r2] r3 into r4;
add r4.total_messages 1u64 into r5;
cast r2 r5 into r6 as Messaging;
set r6 into voice_msg[r2];



function combine_hash_owner_receiver:
input r0 as address.private;
input r1 as address.private;
assert.eq r0 self.caller;
hash.bhp256 r0 into r2 as field;
hash.bhp256 r1 into r3 as field;
add r2 r3 into r4;
cast r0 r2 r1 r4 into r5 as CoBind.record;
output r5 as CoBind.record;
7 changes: 7 additions & 0 deletions examples/uduakobong_voice6/build/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"program": "uduakobong_voice6.aleo",
"version": "0.1.0",
"description": "",
"license": "MIT",
"dependencies": null
}
1 change: 1 addition & 0 deletions examples/uduakobong_voice6/leo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package = []
7 changes: 7 additions & 0 deletions examples/uduakobong_voice6/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"program": "uduakobong_voice6.aleo",
"version": "0.1.0",
"description": "",
"license": "MIT",
"dependencies": null
}
92 changes: 92 additions & 0 deletions examples/uduakobong_voice6/src/main.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// The 'uduakobong_voice6' program.
program uduakobong_voice6.aleo {

//Record for Voice data
record Voice {
owner: address,
receiver: address,
msg: u128,
hash_msg: u128,
}

//Record for combining both owner and receiver
record CoBind {
hash_owner: field,
owner: address,
receiver: address,
bind_hash: field,
}

// struct data for storing user data
struct Messaging {
messenger: field,
total_messages: u64,
}

//Mapping for user data
mapping voice_msg: field => Messaging;

//send voice transition function with the async await js to update state. has 4 inputs
async transition send_voice (owner: address, receiver: address, msg: u128, co_bind: field) -> (Voice, Future){
//hash a message
let hash: u128 = BHP256:: hash_to_u128(msg);

//checks if address calling match owner address
assert(self.caller == owner);

//checks address calling is not a receiver
assert_neq(self.caller, receiver);

//hash the owner
let hash_owner: field = BHP256:: hash_to_field(owner);

//hash the receiver
let hash_receiver: field = BHP256:: hash_to_field(receiver);

//add both [owner and receiver] hash
let add_hash : field = hash_owner + hash_receiver ;

// declaring them into a record -> Voice
let send_from : Voice = Voice {
owner: owner,
receiver: receiver,
msg: msg,
hash_msg: hash
};

//return the record and update the state onchain with the function name - finalize_send_voice
return (send_from, finalize_send_voice(owner, hash));

}
//state being updated
async function finalize_send_voice (owner: address, hash: u128){
//hash the owner
let hash_owner: field = BHP256:: hash_to_field(owner);
// getting the mapping detail, by default mapping is to -> hash_owner and 0 total messages
let total: Messaging = Mapping::get_or_use(voice_msg, hash_owner, Messaging{
messenger: hash_owner,
total_messages: 0u64,
});

//storing/setting the data into the mapping, now the data component will be uopdate to the hash_owner and n total messages
voice_msg.set(hash_owner, Messaging {
messenger: hash_owner,
total_messages: total.total_messages + 1u64,
});
}

transition combine_hash_owner_receiver(owner: address, receiver: address) -> (CoBind){
assert_eq(owner, self.caller);
let hash_owner: field = BHP256::hash_to_field(owner);
let hash_receiver: field = BHP256::hash_to_field(receiver);
let add_hash: field = hash_owner + hash_receiver;

let update_hash: CoBind = CoBind {
hash_owner: hash_owner,
receiver: receiver,
owner: owner,
bind_hash: add_hash,
};
return (update_hash);
}
}

0 comments on commit e4e2d88

Please sign in to comment.