-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc) Implement
Filecoin.MarketAddBalance
(#4679)
- Loading branch information
Showing
4 changed files
with
107 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2019-2024 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use crate::rpc::error::ServerError; | ||
use crate::rpc::mpool::MpoolPushMessage; | ||
use crate::rpc::{ApiPaths, Ctx, Permission, RpcMethod}; | ||
use crate::shim::{address::Address, message::Message, message::MethodNum}; | ||
use cid::Cid; | ||
use fvm_ipld_blockstore::Blockstore; | ||
use fvm_ipld_encoding::RawBytes; | ||
use num_bigint::BigInt; | ||
|
||
const METHOD_ADD_BALANCE: MethodNum = 2; | ||
|
||
pub enum MarketAddBalance {} | ||
impl RpcMethod<3> for MarketAddBalance { | ||
const NAME: &'static str = "Filecoin.MarketAddBalance"; | ||
const PARAM_NAMES: [&'static str; 3] = ["wallet", "address", "amount"]; | ||
const API_PATHS: ApiPaths = ApiPaths::V1; | ||
const PERMISSION: Permission = Permission::Sign; | ||
|
||
type Params = (Address, Address, BigInt); | ||
type Ok = Cid; | ||
|
||
async fn handle( | ||
ctx: Ctx<impl Blockstore + Send + Sync + 'static>, | ||
(wallet, address, amount): Self::Params, | ||
) -> Result<Self::Ok, ServerError> { | ||
let bytes = fvm_ipld_encoding::to_vec(&address)?; | ||
let params = RawBytes::new(bytes); | ||
|
||
let message = Message { | ||
to: Address::MARKET_ACTOR, | ||
from: wallet, | ||
value: amount.into(), | ||
method_num: METHOD_ADD_BALANCE, | ||
params, | ||
..Default::default() | ||
}; | ||
|
||
let smsg = MpoolPushMessage::handle(ctx, (message, None)).await?; | ||
Ok(smsg.cid()) | ||
} | ||
} |
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