Skip to content

Commit

Permalink
fixing program
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 26, 2024
1 parent 223ca63 commit fe744a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
4 changes: 3 additions & 1 deletion crates/cvm-runtime/src/outpost/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,7 @@ pub struct GetConfigResponse {
}

impl GetConfigResponse {
pub fn get_network_for_asset()
pub fn get_network_for_asset(&self, asset_id:AssetId ) -> NetworkId {
self.assets.iter().find(|x| x.asset_id == asset_id).map(|x| x.network_id).expect("network_id")
}
}
23 changes: 10 additions & 13 deletions mantis/node/src/mantis/blackbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ impl BankInput {
}

/// given route and CVM stub with amount, build it to the end
fn build_next(current: &mut CvmProgram, next: &mut [NextItem]) {
fn build_next(current: &mut CvmProgram, next: &mut [NextItem], glt: &GetConfigResponse) {
match next.split_first_mut() {
Some((head, rest)) => match head {
NextItem::Exchange(exchange) => {
let exchange = new_exchange(exchange);
current
.instructions
.push(exchange);
build_next(current, rest);
build_next(current, rest, &glt);
}
NextItem::Spawn(spawn) => {
let spawn = new_spawn(spawn);
let spawn = new_spawn(spawn, glt);
current.instructions.push(spawn);
build_next(spawn.program, rest);
build_next(spawn.program, rest, glt);
}
},
None => {
Expand All @@ -54,11 +54,7 @@ fn build_next(current: &mut CvmProgram, next: &mut [NextItem]) {
}
}

fn new_spawn(spawn: &mut Spawn, glt: GetConfigResponse) -> CvmInstruction {
let exchange_id = match spawn.pool_id {
PoolId::Variant1(id) => id.parse().expect("pool id"),
_ => panic!("exchange_id"),
};
fn new_spawn(spawn: &mut Spawn, glt: &GetConfigResponse) -> CvmInstruction {
let in_asset_id = match spawn.in_asset_id {
InAssetId::Variant1(id) => id.parse().expect("in_asset_id"),
_ => panic!("in_asset_id"),
Expand All @@ -76,9 +72,10 @@ fn new_spawn(spawn: &mut Spawn, glt: GetConfigResponse) -> CvmInstruction {
};

CvmInstruction::Spawn {
give: CvmFundsFilter::one(in_asset_id, in_amount),
want: CvmFundsFilter::one(out_asset_id, Amount::one()),
program: Box::new(CvmProgram::default()),
network_id: todo!(),
salt: todo!(),
assets: todo!(),
}
}

Expand Down Expand Up @@ -111,7 +108,7 @@ fn new_exchange(exchange: &Exchange) -> CvmInstruction {
}

/// `order_accounts` - account of order where to dispatch amounts (part of whole)
async fn route(server: &str, input: BankInput, glt: GetConfigResponse) -> CvmProgram {
async fn route(server: &str, input: BankInput, glt: &GetConfigResponse) -> CvmProgram {
let blackbox: Client = Client::new(server);
let mut route = blackbox
.simulator_router_simulator_router_get(
Expand All @@ -128,6 +125,6 @@ async fn route(server: &str, input: BankInput, glt: GetConfigResponse) -> CvmPro
.expect("at least one route");

let mut program = CvmProgram::default();
build_next(&mut program, &mut route.next);
build_next(&mut program, &mut route.next, glt);
return program;
}

0 comments on commit fe744a6

Please sign in to comment.