-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a11c3d
commit c3f186f
Showing
13 changed files
with
115 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[meta] | ||
creation_timestamp = "1710097915270737 2024-03-10 15:11:55.270737012 -04:00" | ||
|
||
[packages] | ||
dtp = { uuid = "AJE3IMZDUQXBRYQEC7FRNM7BHQ", uuid_custom = false } |
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 |
---|---|---|
@@ -1,44 +1,52 @@ | ||
module dtp::client_registry { | ||
use sui::object::{Self, UID}; | ||
module dtp::user_registry { | ||
use sui::object::{Self, UID, ID}; | ||
use sui::transfer; | ||
use sui::tx_context::{Self, TxContext}; | ||
|
||
const REGISTRY_INVALID_ADDRESS: address = @0x0; | ||
|
||
// | ||
// Owned object. Intended as storage of useful key-value for a DTP client. | ||
// | ||
// As an example, this is how a client find its own localhost (stored in the blob) | ||
// As an example, this is how a client find its own localhost. | ||
// | ||
// DTP will be tested with only one client registry owned per Sui address. | ||
// | ||
// It might work with more than one, but it is not intended to be supported | ||
// on short term (the DTP SDK will prevent to create more than one). | ||
// | ||
// TODO Add general purpose key-value once problem with validators are iron out. | ||
struct Registry has key, store { | ||
struct UserRegistry has key, store { | ||
id: UID, | ||
localhost_blob: vector<u8>, | ||
host_addr: address, | ||
} | ||
|
||
// Constructors | ||
fun init(_ctx: &mut TxContext) { /* NOOP */ } | ||
|
||
public(friend) fun new(ctx: &mut TxContext) : Registry { | ||
Registry { | ||
public fun new(ctx: &mut TxContext) : UserRegistry { | ||
UserRegistry { | ||
id: object::new(ctx), | ||
localhost_blob: vector[], | ||
host_addr: REGISTRY_INVALID_ADDRESS | ||
} | ||
} | ||
|
||
public(friend) fun delete(object: Registry) { | ||
let Registry { id, localhost_blob: _ } = object; | ||
public fun delete(self: UserRegistry) { | ||
let UserRegistry { id, host_addr: _ } = self; | ||
object::delete(id); | ||
} | ||
|
||
public entry fun create( ctx: &mut TxContext ) { | ||
public fun new_and_transfer( localhost_id: ID, ctx: &mut TxContext ) { | ||
let new_obj = new(ctx); | ||
set_host_addr_with_id(&mut new_obj, &localhost_id); | ||
transfer::transfer(new_obj, tx_context::sender(ctx)); | ||
} | ||
|
||
public entry fun set_localhost_blob( registry: &mut Registry, blob : vector<u8> ) { | ||
registry.localhost_blob = blob; | ||
public fun set_host_addr( registry: &mut UserRegistry, host_addr: address ) { | ||
registry.host_addr = host_addr; | ||
} | ||
|
||
public fun set_host_addr_with_id( registry: &mut UserRegistry, host_id: &ID ) { | ||
registry.host_addr = object::id_to_address(host_id); | ||
} | ||
|
||
public fun get_host_addr( registry: &UserRegistry ): address { | ||
registry.host_addr | ||
} | ||
} |
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
Oops, something went wrong.