#智能合约 #联盟 #cosmos-sdk #proto #区块链 #terra-money

terra-proto-rs

用于与 Terra 区块链 v2.10 从 Rust 进行交互的客户端。它可以直接用于 CosmWasm 智能合约或外部区块链 API。

11 个稳定版本

5.2.0 2024 年 3 月 8 日
4.0.4 2024 年 2 月 21 日
4.0.2 2023 年 10 月 24 日
3.0.4 2023 年 8 月 18 日
3.0.1 2023 年 3 月 28 日

#307 in 神奇豆子

Download history 85/week @ 2024-04-09 3/week @ 2024-04-23 3/week @ 2024-06-04 10/week @ 2024-06-11

434 每月下载量

Apache-2.0

2MB
36K SLoC

Rust Terra Proto

用于与 Terra 区块链交互的客户端。可以直接与 CosmWasm 智能合约一起使用,例如在 Alliance Hub 上,或者从外部区块链 API 使用。

CosmWasm 中的使用

将 terra-proto-rs 集成到您的智能合约的 Cargo.toml 中,并将 default-features 设置为 false 以避免导入可能导致您的智能合约失败的库

terra-proto-rs = {version = "5.0.0", default-features = false}

CosmWasm 可用模型

在构建智能合约时,您可以使用以下消息,无需解析结构体,只需导入并使用即可

联盟模块

  • /alliance.alliance.MsgCreateAllianceProposal
  • /alliance.alliance.MsgUpdateAllianceProposal
  • /alliance.alliance.MsgDeleteAllianceProposal
  • /alliance.alliance.MsgCreateAlliance
  • /alliance.alliance.MsgUpdateAlliance
  • /alliance.alliance.MsgDeleteAlliance
  • /alliance.alliance.MsgUpdateParams
  • /alliance.alliance.MsgDelegate
  • /alliance.alliance.MsgUndelegate
  • /alliance.alliance.MsgRedelegate
  • /alliance.alliance.MsgClaimDelegationRewards

Cosmos SDK 基础模块

  • /cosmos.auth.v1beta1.BaseAccount
  • /cosmos.auth.v1beta1.ModuleAccount
  • /cosmos.authz.v1beta1.MsgGrant
  • /cosmos.authz.v1beta1.MsgExec
  • /cosmos.authz.v1beta1.MsgRevoke
  • /cosmos.authz.v1beta1.MsgUpdateParams
  • /cosmos.authz.v1beta1.MsgVerifyInvariant
  • /cosmos.authz.v1beta1.UpdateParams
  • /cosmos.distribution.v1beta1.MsgSetWithdrawAddress
  • /cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward
  • /cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission
  • /cosmos.distribution.v1beta1.MsgFundCommunityPool
  • /cosmos.distribution.v1beta1.MsgCommunityPoolSpend
  • /cosmos.distribution.v1beta1.MsgUpdateParams
  • /cosmos.distribution.v1beta1.MsgSubmitEvidence
  • /cosmos.feegrant.v1beta1.MsgGrantAllowance
  • /cosmos.feegrant.v1beta1.MsgRevokeAllowance
  • /cosmos.feegrant.v1beta1.BasicAllowance
  • /cosmos.feegrant.v1beta1.PeriodicAllowance
  • /cosmos.feegrant.v1beta1.AllowedMsgAllowance
  • /cosmos.gov.v1.MsgSubmitProposal
  • /cosmos.gov.v1.MsgExecLegacyContent
  • /cosmos.gov.v1.MsgVote
  • /cosmos.gov.v1.MsgVoteWeighted
  • /cosmos.gov.v1.MsgDeposit
  • /cosmos.gov.v1.MsgUpdateParams
  • /cosmos.mint.v1beta1.MsgUpdateParams
  • /cosmos.slashing.v1beta1.MsgUnjail
  • /cosmos.staking.v1beta1.MsgUpdateParams
  • /cosmos.staking.v1beta1.MsgCreateValidator
  • /cosmos.staking.v1beta1.MsgEditValidator
  • /cosmos.staking.v1beta1.MsgDelegate
  • /cosmos.staking.v1beta1.MsgUndelegate
  • /cosmos.staking.v1beta1.MsgBeginRedelegate
  • /cosmos.staking.v1beta1.MsgCancelUnbondingDelegation
  • /cosmos.vesting.v1beta1.MsgCreateVestingAccount
  • /cosmos.vesting.v1beta1.MsgCreateVestingAccount
  • /cosmos.vesting.v1beta1.MsgCreateVestingAccount
  • /cosmos.vesting.v1beta1.MsgCreateVestingAccount

CosmWasm

  • /cosmwasm.wasm.v1.MsgStoreCode
  • /cosmwasm.wasm.v1.MsgInstantiateContract
  • /cosmwasm.wasm.v1.MsgInstantiateContract2
  • /cosmwasm.wasm.v1.MsgExecuteContract
  • /cosmwasm.wasm.v1.MsgMigrateContract
  • /cosmwasm.wasm.v1.MsgUpdateAdmin
  • /cosmwasm.wasm.v1.MsgClearAdmin
  • /cosmwasm.wasm.v1.MsgUpdateInstantiateConfig
  • /cosmwasm.wasm.v1.MsgUpdateParams
  • /cosmwasm.wasm.v1.MsgSudoContract
  • /cosmwasm.wasm.v1.MsgPinCodes
  • /cosmwasm.wasm.v1.MsgUnpinCodes
  • /cosmwasm.wasm.v1.MsgStoreAndInstantiateContract

IBC

  • /ibc.applications.transfer.v1.MsgTransfer
  • /ibc.applications.fee.v1.MsgRegisterPayee
  • /ibc.applications.fee.v1.MsgRegisterCounterpartyPayee
  • /ibc.applications.fee.v1.MsgPayPacketFee
  • /ibc.applications.fee.v1.MsgPayPacketFeeAsync
  • /ibc.applications.interchain_accounts.v1.MsgRegisterInterchainAccount
  • /ibc.applications.interchain_accounts.v1.MsgSendTx
  • /ibc.core.channel.v1.MsgChannelCloseConfirm
  • /ibc.core.channel.v1.MsgChannelOpenInit
  • /ibc.core.channel.v1.MsgChannelOpenTry
  • /ibc.core.channel.v1.MsgChannelOpenAck
  • /ibc.core.channel.v1.MsgChannelOpenConfirm
  • /ibc.core.channel.v1.MsgChannelCloseInit
  • /ibc.core.channel.v1.MsgRecvPacket
  • /ibc.core.channel.v1.MsgTimeout
  • /ibc.core.channel.v1.MsgTimeoutOnClose
  • /ibc.core.channel.v1.MsgAcknowledgement
  • /ibc.core.client.v1.MsgCreateClient
  • /ibc.core.client.v1.MsgUpdateClient
  • /ibc.core.client.v1.MsgUpgradeClient
  • /ibc.core.client.v1.MsgSubmitMisbehaviour
  • /ibc.core.connection.v1.MsgConnectionOpenInit
  • /ibc.core.connection.v1.MsgConnectionOpenTry
  • /ibc.core.connection.v1.MsgConnectionOpenAck
  • /ibc.core.connection.v1.MsgConnectionOpenConfirm

Token Factory Module

  • /osmosis.tokenfactory.v1beta1.MsgUpdateParams
  • /osmosis.tokenfactory.v1beta1.MsgCreateDenom
  • /osmosis.tokenfactory.v1beta1.MsgMint
  • /osmosis.tokenfactory.v1beta1.MsgBurn
  • /osmosis.tokenfactory.v1beta1.MsgChangeAdmin
  • /osmosis.tokenfactory.v1beta1.MsgSetDenomMetadata
  • /osmosis.tokenfactory.v1beta1.MsgSetBeforeSendHook
  • /osmosis.tokenfactory.v1beta1.MsgForceTransfer

POB Module

  • /pob.builder.v1.MsgAuctionBid
  • /pob.builder.v1.MsgUpdateParams

POB Module

  • /juno.feeshare.v1.MsgRegisterFeeShare
  • /juno.feeshare.v1.MsgUpdateFeeShare
  • /juno.feeshare.v1.MsgCancelFeeShare
  • /juno.feeshare.v1.MsgUpdateParams

示例

从Alliance Protocol的Alliance Hub智能合约中提取和简化了代表函数的代码片段,见Alliance Hub

fn alliance_delegate(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
    msg: AllianceDelegateMsg,
) -> Result<Response, ContractError> {
    let mut msgs: Vec<CosmosMsg<Empty>> = vec![];
    
    for delegation in msg.delegations {
        ///
        /// Using MsgDelegate from alliance
        ///
        let delegate_msg = MsgDelegate {
            amount: Some(Coin {
                denom: config.alliance_token_denom.clone(),
                amount: delegation.amount.to_string(),
            }),
            delegator_address: env.contract.address.to_string(),
            validator_address: delegation.validator.to_string(),
        };
        ///
        // Creating the Stargate message to be routed on the alliance module
        // from terras blockchain on Response::message
        ///
        msgs.push(CosmosMsg::Stargate {
            type_url: "/alliance.alliance.MsgDelegate".to_string(),
            value: Binary::from(delegate_msg.encode_to_vec()),
        });
    }

    Ok(Response::new()
        .add_attributes(vec![("action", "alliance_delegate")])
        .add_messages(msgs))
}

依赖项

约7-10MB
约210K SLoC