Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
make add_balance payable (#49)
Browse files Browse the repository at this point in the history
* make add_balance payable

* remove dbg

* update code cid for miner
  • Loading branch information
rllola authored Dec 2, 2022
1 parent 0fdea4d commit fa00d5d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion contracts/v0.8/MarketAPI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract MarketAPI {
using PublishStorageDealsCBOR for MarketTypes.PublishStorageDealsReturn;

/// @notice Deposits the received value into the balance held in escrow.
function add_balance(bytes memory provider_or_client) public {
function add_balance(bytes memory provider_or_client) public payable {
bytes memory raw_request = provider_or_client.serializeAddress();

bytes memory raw_response = Actor.call(MarketTypes.AddBalanceMethodNum, MarketTypes.ActorCode, raw_request);
Expand Down
5 changes: 3 additions & 2 deletions contracts/v0.8/utils/Actor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ library Actor {
bytes memory raw_response = new bytes(MAX_RAW_RESPONSE_SIZE);

uint len;
uint amount = msg.value;

require(actor_code[0] == 0x00, "actor address needs to be type ID");

Expand Down Expand Up @@ -59,8 +60,8 @@ library Actor {
// no params

// FIXME set inputSize according to the input length
// call(gasLimit, to, value, inputOffset, inputSize, outputOffset, outputSize)
if iszero(call(GAS_LIMIT, CALL_ACTOR_PRECOMPILE_ADDR, 0x00, input, 0x100, raw_response, MAX_RAW_RESPONSE_SIZE)) {
// call(gasLimit, to, amount, inputOffset, inputSize, outputOffset, outputSize)
if iszero(call(GAS_LIMIT, CALL_ACTOR_PRECOMPILE_ADDR, amount, input, 0x100, raw_response, MAX_RAW_RESPONSE_SIZE)) {
revert(0, 0)
}
}
Expand Down
Binary file modified testing/builtin-actors-devnet-wasm.car
Binary file not shown.
12 changes: 1 addition & 11 deletions testing/market/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ fvm_shared = { version = "3.0.0-alpha.13" }
fvm = { version = "3.0.0-alpha.12", default-features = false, features = ["m2-native"] }
fvm_ipld_encoding = { version = "0.3.0" }
fvm_integration_tests = { version = "0.1.1-alpha.1", git = "https://github.com/rllola/ref-fvm", branch = "lola/fixes" }
# fvm_integration_tests = { version = "0.1.1-alpha.1", path = "../../../ref-fvm/testing/integration" }


serde = { version = "1.0", features = ["derive"] }
serde_tuple = "0.5"
Expand All @@ -29,12 +27,4 @@ fvm_ipld_hamt = { version = "0.6.1", git = "https://github.com/rllola/ref-fvm",
fvm_ipld_amt = { version = "0.5.0", git = "https://github.com/rllola/ref-fvm", branch = "lola/fixes" }
fvm_ipld_blockstore = { version = "0.1.1", git = "https://github.com/rllola/ref-fvm", branch = "lola/fixes" }
fvm = { version = "3.0.0-alpha.12", git = "https://github.com/rllola/ref-fvm", branch = "lola/fixes", default-features = false, features = ["m2-native"] }
fvm_sdk = { version = "3.0.0-alpha.15", git = "https://github.com/rllola/ref-fvm", branch = "lola/fixes" }

# fvm_shared = { version = "3.0.0-alpha.13", path = "../../../ref-fvm/shared" }
# fvm_ipld_encoding = { version = "0.3.0", path = "../../../ref-fvm/ipld/encoding" }
# fvm_ipld_hamt = { version = "0.6.1", path = "../../../ref-fvm/ipld/hamt" }
# fvm_ipld_amt = { version = "0.5.0", path = "../../../ref-fvm/ipld/amt" }
# fvm_ipld_blockstore = { version = "0.1.1", path = "../../../ref-fvm/ipld/blockstore" }
# fvm = { version = "3.0.0-alpha.12", path = "../../../ref-fvm/fvm", default-features = false, features = ["m2-native"] }
# fvm_sdk = { version = "3.0.0-alpha.15", path = "../../../ref-fvm/sdk" }
fvm_sdk = { version = "3.0.0-alpha.15", git = "https://github.com/rllola/ref-fvm", branch = "lola/fixes" }
15 changes: 7 additions & 8 deletions testing/market/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use fvm_integration_tests::bundle;
use fvm_ipld_encoding::{strict_bytes, tuple::*};
use fvm_shared::state::StateTreeVersion;
use fvm_shared::version::NetworkVersion;
use fvm_shared::econ::TokenAmount;
use fvm_ipld_blockstore::MemoryBlockstore;
use fvm_shared::address::Address;
use std::env;
Expand Down Expand Up @@ -37,6 +38,9 @@ fn main() {

let sender: [Account; 1] = tester.create_accounts().unwrap();

// Our account address is 100 so hex"0064"
// dbg!(sender[0]);

// Instantiate machine
tester.instantiate_machine(DummyExterns).unwrap();

Expand Down Expand Up @@ -82,21 +86,16 @@ fn main() {
gas_limit: 1000000000,
method_num: 2,
sequence: 1,
params: RawBytes::new(hex::decode("5864467FAFEF000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020066000000000000000000000000000000000000000000000000000000000000").unwrap()),
value: TokenAmount::from_atto(1_000),
params: RawBytes::new(hex::decode("5864467FAFEF000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020064000000000000000000000000000000000000000000000000000000000000").unwrap()),
..Message::default()
};

let res = executor
.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();

if res.msg_receipt.exit_code.value() != 33 {
dbg!(&res);
}

assert_eq!(res.msg_receipt.exit_code.value(), 33);
assert_eq!(hex::encode(res.msg_receipt.return_data.bytes()), "08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000136163746f72206572726f7220636f646520313600000000000000000000000000");

assert_eq!(res.msg_receipt.exit_code.value(), 0);

println!("Calling `withdraw_balance`");

Expand Down
4 changes: 2 additions & 2 deletions testing/miner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn main() {

let actor_state = ActorState {
// CID of Accounts actor. You get this as output from builtin-actors compiling process
code: Cid::from_str("bafk2bzacedwtrdnnb777mbyh2z5viy4m24gfxxrlq7tbcf6is7yo4sqpm4iv4").unwrap(),
code: Cid::from_str("bafk2bzacecshmegs4rnghc5y3pr3dayjbuha3o3gznnd74s33rzwkxh2kcrsg").unwrap(),
// code: Cid::from_str("bafk2bzacecj7v5ur5qk4vn3xbvgsizl35e42l3yaankmxu6dcoouv4mkphsjq").unwrap(),
state: cid,
sequence: 0,
Expand Down Expand Up @@ -110,7 +110,7 @@ fn main() {

let exec_params = fil_actor_init::ExecParams{
// CID of StorageMiner actor. You get this as output from builtin-actors compiling process
code_cid: Cid::from_str("bafk2bzacedexvfprcccv3kq4ausjfz4ip7uvudxchkcglg7sz5z42jwvhlyn2").unwrap(),
code_cid: Cid::from_str("bafk2bzacebwhcprlqkaeg7hlldnb4jqtklayicnckglll6ses7ytru4donols").unwrap(),
// code_cid: Cid::from_str("bafk2bzacedgixfd465634uihet3u57vugbbp6s5sseb76phti3cexx66ers3i").unwrap(),
constructor_params: RawBytes::serialize(constructor_params).unwrap(),
};
Expand Down

0 comments on commit fa00d5d

Please sign in to comment.