#bindings #cyber #messages #query #routes #graph #energy

bin+lib cyber-std

Bindings for CustomMsg and CustomQuery for the Cyber

5 unstable releases

new 0.3.0 Oct 15, 2024
0.2.2 Aug 27, 2022
0.2.1 Jun 2, 2022
0.2.0 Apr 26, 2022
0.1.0 Mar 1, 2022

#638 in Magic Beans

Download history 2/week @ 2024-07-05 4/week @ 2024-07-26 2/week @ 2024-08-02 2/week @ 2024-08-30 7/week @ 2024-09-06 7/week @ 2024-09-13 23/week @ 2024-09-20 16/week @ 2024-09-27 6/week @ 2024-10-04 165/week @ 2024-10-11

210 downloads per month
Used in cyber-std-test

Unlicense

43KB
1K SLoC

Cyber Bindings for CosmWasm

Crates.io Crates.io

This crate provides Cyber-specific bindings to enable your CosmWasm smart contracts to interact with the Cyber blockchain by exposing messages and queriers that can be emitted and used from within your contract.

Bindings

Currently, the Cyber bindings include:

  • Query support for:
    • Graph
      • ParticlesAmount
      • CyberlinksAmount
    • Bandwidth
      • BandwidthPrice
      • BandwidthLoad
      • BandwidthTotal
      • NeuronBandwidth
    • Rank
      • ParticleRank
    • Energy
      • SourceRoutes
      • SourceRoutedEnergy
      • DestinationRoutedEnergy
      • Route
    • DMN
      • Thought
      • ThoughtStats
      • ThoughtLowestFee
    • Liquidity
      • PoolParams
      • PoolLiquidity
      • PoolSupply
      • PoolPrice
      • PoolAddress
  • Messages
    • Graph
      • MsgCyberlink
    • Resources
      • MsgInvestmint
    • Energy
      • MsgCreateRoute
      • MsgEditRoute
      • MsgEditRouteName
      • MsgDeleteRoute
    • DMN
      • MsgCreateThought
      • MsgForgetThought
      • MsgChangeThoughtInput
      • MsgChangeThoughtPeriod
      • MsgChangeThoughtBlock
      • MsgChangeThoughtGasPrice
      • MsgChangeThoughtParticle
      • MsgChangeThoughtName
    • Liquidity
      • MsgCreatePool
      • MsgDepositWithinBath
      • MsgWithdrawWithinBath
      • MsgSwapWithinBath

Usage

Querying

In order to use the query functions enabled by the bindings, create a CyberQuerier instance within your contract logic. You can access all the enabled queries through this object.

// src/contract.rs
use cosmwasm_std::Coin;
use cyber_std::{ CyberQuerier, RankValueResponse };

...

// handler
pub fn try_something(
    deps: Deps,
    _env: Env,
    particle: String,
    ...
) -> StdResult<ParticleRankResponse> {
    let querier = CyberQuerier::new(&deps.querier);
    let res: ParticleRankResponse = querier.query_particle_rank(particle)?;
    ...
    Ok(res)
}

Creating Messages

You may want your contract to perform messages such as MsgCyberlink operations at the end of its execution. To do this, create a message using the predefined functions:

  • create_cyberlink_msg
use cosmwasm_std::CosmosMsg;
use cyber_std::{ create_cyberlink_msg, CyberMsgWrapper };

...

pub fn try_something(
    deps: DepsMut,
    env: Env,
    links: Vec<Link>,
    ...
) -> Result<Response, ContractError> {
    ...
    let contract_addr = env.contract.address;
    let msg: CosmosMsg<CyberMsgWrapper> = create_cyberlink_msg(contract_addr.into(), links);
    
    let res = Response::new()
          .add_message(msg);
    Ok(res)
}

Dependencies

~4.5–6.5MB
~133K SLoC