-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/add get block with txs (#71)
* feat: add custom GetBlockWithTxs for lbm --------- Signed-off-by: zemyblue <[email protected]> Co-authored-by: zemyblue <[email protected]> Co-authored-by: Youngtaek Yoon <[email protected]>
- Loading branch information
1 parent
b455367
commit 08f1c2e
Showing
6 changed files
with
114 additions
and
4 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
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,73 @@ | ||
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; | ||
import { coins, MsgSendEncodeObject, QueryClient } from "@cosmjs/stargate"; | ||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; | ||
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"; | ||
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx"; | ||
|
||
import { makeLinkPath } from "../../paths"; | ||
import { SigningFinschiaClient } from "../../signingfinschiaclient"; | ||
import { | ||
defaultSigningClientOptions, | ||
faucet, | ||
makeRandomAddress, | ||
pendingWithoutSimapp, | ||
simapp, | ||
} from "../../testutils.spec"; | ||
import { longify } from "../../utils"; | ||
import { setupTx2Extension, Tx2Extension } from "./queries"; | ||
|
||
async function makeClientWithTx2(rpcUrl: string): Promise<[QueryClient & Tx2Extension, Tendermint34Client]> { | ||
const tmClient = await Tendermint34Client.connect(rpcUrl); | ||
return [QueryClient.withExtensions(tmClient, setupTx2Extension), tmClient]; | ||
} | ||
|
||
async function sendDummyTx() { | ||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic, { | ||
hdPaths: [makeLinkPath(0)], | ||
prefix: simapp.prefix, | ||
}); | ||
const client = await SigningFinschiaClient.connectWithSigner( | ||
simapp.tendermintUrl, | ||
wallet, | ||
defaultSigningClientOptions, | ||
); | ||
const defaultFee = { | ||
amount: coins(250000, simapp.denomFee), | ||
gas: "1500000", | ||
}; | ||
const msg: MsgSend = { | ||
fromAddress: faucet.address0, | ||
toAddress: makeRandomAddress(), | ||
amount: coins(1234, simapp.denomFee), | ||
}; | ||
const dummyMsg: MsgSendEncodeObject = { | ||
typeUrl: "/cosmos.bank.v1beta1.MsgSend", | ||
value: msg, | ||
}; | ||
const signed = await client.sign(faucet.address0, [dummyMsg], defaultFee, ""); | ||
return await client.broadcastTx(Uint8Array.from(TxRaw.encode(signed).finish())); | ||
} | ||
|
||
describe("Tx2Extension", () => { | ||
let client: QueryClient & Tx2Extension; | ||
let tmClient: Tendermint34Client; | ||
beforeAll(async () => { | ||
const res = await makeClientWithTx2(simapp.tendermintUrl); | ||
client = res[0]; | ||
tmClient = res[1]; | ||
}); | ||
afterAll(() => { | ||
tmClient.disconnect(); | ||
}); | ||
|
||
it("getBlockWithTxs", async () => { | ||
pendingWithoutSimapp(); | ||
|
||
const txRes = await sendDummyTx(); | ||
const response = await client.tx2.getBlockWithTxs(longify(txRes.height)); | ||
|
||
expect(response.txs).toBeDefined(); | ||
expect(response.blockId).toBeDefined(); | ||
expect(response.block).toBeDefined(); | ||
}); | ||
}); |
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,34 @@ | ||
import { | ||
createPagination, | ||
createProtobufRpcClient, | ||
QueryClient, | ||
setupTxExtension, | ||
TxExtension, | ||
} from "@cosmjs/stargate"; | ||
import { GetBlockWithTxsResponse, ServiceClientImpl } from "lbmjs-types/lbm/tx/v1beta1/service"; | ||
import Long from "long"; | ||
|
||
export interface Tx2Extension extends TxExtension { | ||
readonly tx2: { | ||
readonly getBlockWithTxs: (height: Long, paginationKey?: Uint8Array) => Promise<GetBlockWithTxsResponse>; | ||
}; | ||
} | ||
|
||
export function setupTx2Extension(base: QueryClient): Tx2Extension { | ||
const txExtension = setupTxExtension(base); | ||
const rpc = createProtobufRpcClient(base); | ||
|
||
// GetBlockWithTxs(request: GetBlockWithTxsRequest): Promise<GetBlockWithTxsResponse>; | ||
const queryService = new ServiceClientImpl(rpc); | ||
return { | ||
tx: txExtension.tx, | ||
tx2: { | ||
getBlockWithTxs: async (height: Long, paginationKey?: Uint8Array) => { | ||
return await queryService.GetBlockWithTxs({ | ||
height: height, | ||
pagination: createPagination(paginationKey), | ||
}); | ||
}, | ||
}, | ||
}; | ||
} |