[fastx programmability] allowing objects to own other objects #99
Closed
Description
Step 1: fleshing out addresses and authenticators
Today, every object has an owner: FastPayAddress
field, where a FastPayAddress
is just a 32 byte public key. In the future, an address should be the hash of an authenticator, e.g.
enum Authenticator {
PubKey(PublicKeyBytes), // existing
Object(ObjectID), // new, purpose of this issue
// ... K-of-N multisig, whatever else we want
}
pub struct Address(Vec<u8>)
impl Address {
pub fn new(auth: Authenticator) -> Self {
// .. hash authenticator to build the address
}
}
A transaction will also need to include an authenticator
for the sender instead of an address.
Step 2: expand tx authentication logic to cover the new authenticator types
Today, that logic lives here. This should be extended to
- Look at the
owner
address of each input object - If the address was derived from the
PubKey
variant, it should match the hash of the pubkey in the tx'sauthenticator
- If the address was derived from the
Object(id)
variant,id
should also be an input to the transaction
Step 3: expose Move primitive for transferring an object to another object
This (almost) already exists here. The semantics are much the same as Transfer::transfer
: switch the object's owner
field to the given ObjectID
.
Step 4: define collection types and other code that use this new primitive in interesting ways. E.g.
struct Map {
/// a heterogenous map keyed by object ID's
struct Map has key { id: ID, children: vector<IDBytes> }
public fun insert<T: key>(m: &mut Map, child: T) {
Vector::push_back(&mut m.childen, ID::id(&child));
Transfer::transfer_to_id(child, ID::id(&m))
}
// ... checking membership, removing items, transferring Map itself, etc.
}
struct Gallery {
// a heterogenous collection of objects
struct Gallery has key { id : ID, num_items: u64 }
public fun add<T: key>(g: &mut Gallery, t: T) {
g.num_items += 1;
Transfer::transfer_to_id(child, ID::id(&t))
}
// ... removing items, transferring Gallery itself, etc.
}
Metadata
Assignees
Labels
No labels