Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: We add and track crypto digests to orders and objects #117

Merged
merged 15 commits into from
Jan 6, 2022
Prev Previous commit
Next Next commit
Added a previous_transaction field to object
  • Loading branch information
George Danezis committed Jan 6, 2022
commit a7252353f5aa863582eb6e1c03ba028e984fdf9f
21 changes: 17 additions & 4 deletions fastx_programmability/adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn execute<E: Debug, S: ResourceResolver<Error = E> + ModuleResolver<Error =
&type_args,
object_args,
pure_args,
ctx,
&ctx,
)?;

let vm = MoveVM::new(natives)
Expand Down Expand Up @@ -108,7 +108,9 @@ pub fn execute<E: Debug, S: ResourceResolver<Error = E> + ModuleResolver<Error =
gas_object,
gas_used,
gas_budget,
&ctx,
)?;

Ok(())
}
ExecutionResult::Fail { error, gas_used } => {
Expand Down Expand Up @@ -169,7 +171,12 @@ pub fn publish<E: Debug, S: ResourceResolver<Error = E> + ModuleResolver<Error =
let _ = state_view;

// Create module objects and write them to the store
let module_object = Object::new_module(module, sender, SequenceNumber::new());
let module_object = Object::new_module(
module,
sender,
SequenceNumber::new(),
ctx.get_transaction_digest(),
gdanezis marked this conversation as resolved.
Show resolved Hide resolved
);
written_refs.push(module_object.to_object_reference());
state_view.write_object(module_object);
}
Expand Down Expand Up @@ -229,6 +236,7 @@ fn process_successful_execution<
mut gas_object: Object,
mut gas_used: u64,
gas_budget: u64,
ctx: &TxContext,
) -> Result<(), FastPayError> {
for (mut obj, new_contents) in mutable_refs {
match &mut obj.data {
Expand Down Expand Up @@ -270,7 +278,12 @@ fn process_successful_execution<
old_object.next_sequence_number = sequence_number;
old_object
} else {
let obj = Object::new_move(move_obj, recipient, SequenceNumber::new());
let obj = Object::new_move(
move_obj,
recipient,
SequenceNumber::new(),
ctx.get_transaction_digest(),
);
gas_used += calculate_object_creation_cost(&obj);
obj
};
Expand Down Expand Up @@ -328,7 +341,7 @@ fn resolve_and_type_check(
type_args: &[TypeTag],
object_args: Vec<Object>,
mut pure_args: Vec<Vec<u8>>,
ctx: TxContext,
ctx: &TxContext,
) -> Result<TypeCheckSuccess, FastPayError> {
// resolve the function we are calling
let (function_signature, module_id) = match module_object.data {
Expand Down
7 changes: 6 additions & 1 deletion fastx_programmability/adapter/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ fn create_genesis_module_objects() -> Result<Genesis> {
*struct_name
);
}
Object::new_module(m, owner, SequenceNumber::new())
Object::new_module(
m,
owner,
SequenceNumber::new(),
TransactionDigest::new([0; 32]),
gdanezis marked this conversation as resolved.
Show resolved Hide resolved
)
})
.collect();
Ok(Genesis {
Expand Down
5 changes: 5 additions & 0 deletions fastx_types/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ impl TxContext {
id
}

/// Return the transaction digest, to include in new objects
pub fn get_transaction_digest(&self) -> TransactionDigest {
gdanezis marked this conversation as resolved.
Show resolved Hide resolved
self.digest
}

// TODO(https://github.com/MystenLabs/fastnft/issues/89): temporary hack for Move compatibility
pub fn to_bcs_bytes_hack(&self) -> Vec<u8> {
let sender = FastPayAddress::default();
Expand Down
12 changes: 11 additions & 1 deletion fastx_types/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use move_binary_format::CompiledModule;
use move_core_types::{account_address::AccountAddress, language_storage::StructTag};

use crate::{
base_types::{BcsSignable, FastPayAddress, ObjectID, ObjectRef, SequenceNumber},
base_types::{
BcsSignable, FastPayAddress, ObjectID, ObjectRef, SequenceNumber, TransactionDigest,
},
gas_coin::GasCoin,
};

Expand Down Expand Up @@ -86,7 +88,10 @@ pub struct Object {
pub data: Data,
/// The authenticator that unlocks this object (eg. public key, or other)
pub owner: FastPayAddress,
/// The version of this object, starting at zero
pub next_sequence_number: SequenceNumber,
/// The digest of the order that created or last mutated this object
pub previous_transaction: TransactionDigest,
}

impl BcsSignable for Object {}
Expand All @@ -97,25 +102,29 @@ impl Object {
o: MoveObject,
owner: FastPayAddress,
next_sequence_number: SequenceNumber,
previous_transaction: TransactionDigest,
) -> Self {
Object {
data: Data::Move(o),
owner,
next_sequence_number,
previous_transaction,
}
}

pub fn new_module(
m: CompiledModule,
owner: FastPayAddress,
next_sequence_number: SequenceNumber,
previous_transaction: TransactionDigest,
) -> Self {
let mut bytes = Vec::new();
m.serialize(&mut bytes).unwrap();
Object {
data: Data::Module(bytes),
owner,
next_sequence_number,
previous_transaction,
}
}

Expand Down Expand Up @@ -172,6 +181,7 @@ impl Object {
owner,
data,
next_sequence_number,
previous_transaction: TransactionDigest::new([0; 32]),
}
}

Expand Down