Skip to content

Commit

Permalink
Serialise bigint as idiomatic Filecoin form
Browse files Browse the repository at this point in the history
Without this it naively serialises using the underlying Rust BigInt
representation:

	[sign,[data,data,...]]
  • Loading branch information
rvagg committed Feb 8, 2024
1 parent 0f381a6 commit a3df645
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion actors/verifreg/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{ActorError, AllocationID};
use crate::{ClaimID, DataCap};
use fil_actors_runtime::runtime::Runtime;
use fil_actors_runtime::EventBuilder;
use fvm_shared::bigint::bigint_ser::BigIntSer;
use fvm_shared::ActorID;

/// Indicates a new value for a verifier's datacap balance.
Expand All @@ -18,7 +19,7 @@ pub fn verifier_balance(
&EventBuilder::new()
.typ("verifier-balance")
.field_indexed("verifier", &verifier)
.field("balance", new_balance)
.field("balance", &BigIntSer(new_balance))
.build()?,
)
}
Expand Down
6 changes: 3 additions & 3 deletions actors/verifreg/tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Harness {
EventBuilder::new()
.typ("verifier-balance")
.field_indexed("verifier", &verifier_resolved.id().unwrap())
.field("balance", &allowance)
.field("balance", &BigIntSer(&allowance))
.build()?,
);

Expand All @@ -166,7 +166,7 @@ impl Harness {
EventBuilder::new()
.typ("verifier-balance")
.field_indexed("verifier", &verifier.id().unwrap())
.field("balance", &DataCap::zero())
.field("balance", &BigIntSer(&DataCap::zero()))
.build()?,
);
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, self.root);
Expand Down Expand Up @@ -234,7 +234,7 @@ impl Harness {
EventBuilder::new()
.typ("verifier-balance")
.field_indexed("verifier", &verifier.id().unwrap())
.field("balance", &(verifier_balance - allowance))
.field("balance", &BigIntSer(&(verifier_balance - allowance)))
.build()?,
);
let ret = rt.call::<VerifregActor>(
Expand Down
3 changes: 2 additions & 1 deletion actors/verifreg/tests/verifreg_actor_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fvm_shared::address::Address;
use fvm_shared::bigint::bigint_ser::BigIntSer;
use lazy_static::lazy_static;

mod harness;
Expand Down Expand Up @@ -447,7 +448,7 @@ mod clients {
EventBuilder::new()
.typ("verifier-balance")
.field_indexed("verifier", &VERIFIER.id().unwrap())
.field("balance", &(allowance_verifier - allowance_client))
.field("balance", &BigIntSer(&(allowance_verifier - allowance_client)))
.build()
.unwrap(),
);
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/src/util/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_ipld_encoding::BytesDe;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;
use fvm_shared::bigint::bigint_ser::BigIntSer;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::crypto::signature::Signature;
use fvm_shared::crypto::signature::SignatureType;
Expand Down Expand Up @@ -764,7 +765,7 @@ pub fn verifier_balance_event(verifier: ActorID, data_cap: DataCap) -> EmittedEv
event: EventBuilder::new()
.typ("verifier-balance")
.field_indexed("verifier", &verifier)
.field("balance", &data_cap)
.field("balance", &BigIntSer(&data_cap))
.build()
.unwrap(),
}
Expand Down

0 comments on commit a3df645

Please sign in to comment.