Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add send method for client #85

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.0] - 2024-03-12
### Added
- `@rarimo/client` - Send method

## [2.0.0] - 2024-03-06
### Added
- `@rarimo/client` - Wallet injection
Expand Down Expand Up @@ -523,7 +527,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Under the hood changes
- Initiated repo with `@rarimo/provider` and `@rarimo/nft-checkout` packages

[Unreleased]: https://github.com/rarimo/js-sdk/compare/2.0.0...HEAD
[Unreleased]: https://github.com/rarimo/js-sdk/compare/2.1.0...HEAD
[2.1.0]: https://github.com/rarimo/js-sdk/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.34...2.0.0
[2.0.0-rc.34]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.33...2.0.0-rc.34
[2.0.0-rc.33]: https://github.com/rarimo/js-sdk/compare/2.0.0-rc.32...2.0.0-rc.33
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/bridge",
"version": "2.0.0",
"version": "2.1.0",
"description": "Internal tools that other Rarimo packages use to bridge tokens.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/client",
"version": "2.0.0",
"version": "2.1.0",
"description": "The Rarimo chain client",
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions packages/client/src/broadcaster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GeneratedType } from '@cosmjs/proto-signing'

import { MsgExec } from '@/codec/cosmos/authz/v1beta1/tx'
import { MsgSend } from '@/codec/cosmos/bank/v1beta1/tx'
import { Coin } from '@/codec/cosmos/base/v1beta1/coin'
import {
MsgWithdrawDelegatorReward,
Expand Down Expand Up @@ -119,6 +120,14 @@ export const makeRarimoBroadcaster = async (
])
},

// bank
send: (fromAddress: string, toAddress: string, amount: Coin[]) => {
return broadcaster<MsgSend>(
MessageTypeUrls.Send,
MsgSend,
)(MsgSend.fromPartial({ fromAddress, toAddress, amount }))
},

// gov
voteProposal: (voter: string, proposalId: number, option: VoteOption) => {
return broadcaster<MsgVote>(
Expand Down
91 changes: 91 additions & 0 deletions packages/client/src/codec/cosmos/bank/v1beta1/tx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* eslint-disable */
import _m0 from 'protobufjs/minimal'

import { type DeepPartial, type Exact, isSet } from '@/codec/helpers'

import { Coin } from '../../base/v1beta1/coin'

export const protobufPackage = 'cosmos.bank.v1beta1'

/** MsgSend represents a message to send coins from one account to another. */
export interface MsgSend {
fromAddress: string
toAddress: string
amount: Coin[]
}

function createBaseMsgSend(): MsgSend {
return { fromAddress: '', toAddress: '', amount: [] }
}

export const MsgSend = {
encode(
message: MsgSend,
writer: _m0.Writer = _m0.Writer.create(),
): _m0.Writer {
if (message.fromAddress !== '') {
writer.uint32(10).string(message.fromAddress)
}
if (message.toAddress !== '') {
writer.uint32(18).string(message.toAddress)
}
for (const v of message.amount) {
Coin.encode(v!, writer.uint32(26).fork()).ldelim()
}
return writer
},

decode(input: _m0.Reader | Uint8Array, length?: number): MsgSend {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input)
const end = length === undefined ? reader.len : reader.pos + length
const message = createBaseMsgSend()
while (reader.pos < end) {
const tag = reader.uint32()
switch (tag >>> 3) {
case 1:
message.fromAddress = reader.string()
break
case 2:
message.toAddress = reader.string()
break
case 3:
message.amount.push(Coin.decode(reader, reader.uint32()))
break
default:
reader.skipType(tag & 7)
break
}
}
return message
},

fromJSON(object: any): MsgSend {
return {
fromAddress: isSet(object.fromAddress) ? String(object.fromAddress) : '',
toAddress: isSet(object.toAddress) ? String(object.toAddress) : '',
amount: Array.isArray(object?.amount)
? object.amount.map((e: any) => Coin.fromJSON(e))
: [],
}
},

toJSON(message: MsgSend): unknown {
const obj: any = {}
message.fromAddress !== undefined && (obj.fromAddress = message.fromAddress)
message.toAddress !== undefined && (obj.toAddress = message.toAddress)
if (message.amount) {
obj.amount = message.amount.map(e => (e ? Coin.toJSON(e) : undefined))
} else {
obj.amount = []
}
return obj
},

fromPartial<I extends Exact<DeepPartial<MsgSend>, I>>(object: I): MsgSend {
const message = createBaseMsgSend()
message.fromAddress = object.fromAddress ?? ''
message.toAddress = object.toAddress ?? ''
message.amount = object.amount?.map(e => Coin.fromPartial(e)) || []
return message
},
}
7 changes: 7 additions & 0 deletions packages/client/src/types/broadcaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export type RarimoBroadcaster = {
validatorAddress: string,
) => Promise<DeliverTxResponse>

// bank
send: (
fromAddress: string,
toAddress: string,
amount: Coin[],
) => Promise<DeliverTxResponse>

// gov
voteProposal(
voter: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/nft-checkout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/nft-checkout",
"version": "2.0.0",
"version": "2.1.0",
"description": "Features of the Rarimo SDK that create cross-chain transactions based on the Rarimo protocol.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/provider",
"version": "2.0.0",
"version": "2.1.0",
"description": "A common interface for access to wallets (EVM and non-EVM) in the Rarimo SDK, used by packages that provide access to wallets on specific chains such as @rarimo/providers-evm, @rarimo/providers-solana, and @rarimo/providers-near.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/providers-evm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/providers-evm",
"version": "2.0.0",
"version": "2.1.0",
"description": "Features of the Rarimo SDK that provide access to wallets and the ability to interact with them on EVM-compatible blockchains.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/providers-near/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/providers-near",
"version": "2.0.0",
"version": "2.1.0",
"description": "Features of the Rarimo SDK that provide access to wallets and the ability to interact with them on the NEAR blockchain.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/providers-solana/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/providers-solana",
"version": "2.0.0",
"version": "2.1.0",
"description": "Features of the Rarimo SDK that provide access to wallets and the ability to interact with them on the Solana blockchain.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-nft-checkout/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/react-nft-checkout",
"version": "2.0.0",
"version": "2.1.0",
"description": "React components that you can use in your UI to create cross-chain transactions with the Rarimo protocol.",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/react-provider",
"version": "2.0.0",
"version": "2.1.0",
"description": "Tools to connect to wallets in React applications through the Rarimo SDK.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/shared",
"version": "2.0.0",
"version": "2.1.0",
"description": "Utility functions, types and constants shared across Rarimo packages.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rarimo/swap",
"version": "2.0.0",
"version": "2.1.0",
"description": "Internal tools that other Rarimo packages use to swap tokens.",
"repository": {
"type": "git",
Expand Down
Loading