Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Dec 2, 2022
2 parents 69c4d0a + 6036326 commit c478ccc
Show file tree
Hide file tree
Showing 710 changed files with 47,074 additions and 343,437 deletions.
359 changes: 356 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jackal.js-protos",
"version": "1.1.0",
"version": "1.1.3",
"description": "Package of all protos used by Jackal.js",
"keywords": [
"jackal",
Expand All @@ -10,14 +10,10 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"packit": "tsc && npm pack --pack-destination packs",
"fix": "npm run fixlong && npm run fixquery && npm run fixfields && npm run fixexport && find . -name '*.ts-e' -exec rm -R {} \\;",
"fixlong": "find ./src -name '*.ts' -exec sed -i -e 's/^import \\* as Long/import Long/' {} \\;",
"fixquery": "find ./src -name '*.ts' -exec sed -i -e 's/ query=null / query /' {} \\;",
"fixexport": "find ./src -name 'index.ts' -exec sed -i -e 's/^const types = \\[/export const types = \\[/' {} \\;",
"fixfields": "find ./src -name '*.ts' -exec sed -i -e 's/\tlet structure = { fields: \\[\\] }/\tlet structure: { fields: any\\[\\] } = { fields: \\[\\] }/' {} \\;",
"push": "tsc && npm publish",
"build": "tsc && tscpaths -p tsconfig.json -s ./src -o ./dist",
"compile": "./scripts/protocgen.sh",
"packit": "npm run build && npm pack --pack-destination packs",
"push": "npm run build && npm publish",
"test": "echo \"Error: no tests included\" && exit 1"
},
"contributors": [
Expand All @@ -43,9 +39,12 @@
"dependencies": {
"@cosmjs/launchpad": "^0.27.1",
"@cosmjs/proto-signing": "^0.28.13",
"@cosmjs/stargate": "^0.28.13"
"@cosmjs/stargate": "^0.28.13",
"@improbable-eng/grpc-web": "^0.15.0",
"ts-proto": "^1.131.0"
},
"devDependencies": {
"@modii/tscpaths": "^0.2.3",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "^6.7.2",
Expand Down
24 changes: 24 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -uox pipefail

# Get protoc executions
go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null

# Get cosmos sdk from github
go get github.com/cosmos/[email protected] 2>/dev/null

cd 'src'
echo "Generating proto code"

# Generate Static Protos
static_dirs_regex='(bank|distribution|gov|staking)'
static_proto_dirs=$(find -E . -iregex ".*\/staticProto\/cosmos\/$static_dirs_regex.*\.proto")
for file in $static_proto_dirs; do
buf generate --template ./cfg/buf.gen.yaml $file
done

# Generate Custom Protos
proto_dirs=$(find ./proto -name '*.proto')
for file in $proto_dirs; do
buf generate --template ./cfg/buf.gen.yaml $file
done
17 changes: 17 additions & 0 deletions src/cfg/buf.gen.gogo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: v1beta1
plugins:
- name: gocosmos
out: ..
opt:
- plugins=grpc
- Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types
- Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types
- Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types
- Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types
- Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types
- Mcosmos/orm/v1beta1/orm.proto=github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1beta1
- name: grpc-gateway
out: ..
opt:
- logtostderr=true
- allow_colon_final_segments=true
9 changes: 9 additions & 0 deletions src/cfg/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v1beta1
plugins:
- name: ts
out: ./postgen
path: ../node_modules/ts-proto/protoc-gen-ts_proto
strategy: all
opt:
- esModuleInterop=true
- outputClientImpl=grpc-web
48 changes: 21 additions & 27 deletions src/customBroadcast.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,56 @@
import { StdFee } from '@cosmjs/launchpad'
import { EncodeObject, OfflineSigner, Registry } from '@cosmjs/proto-signing'
import { SigningStargateClient } from '@cosmjs/stargate'
import { DeliverTxResponse, SigningStargateClient } from '@cosmjs/stargate'

/**
* Jackal Custom Protos
*/
import { types as cosmTypes } from './protos/CosmWasm/wasmd/cosmwasm.wasm.v1/module'
import { types as dsigTypes } from './protos/jackal-dao/canine/jackaldao.canine.dsig/module'
import { types as filetreeTypes } from './protos/jackal-dao/canine/jackaldao.canine.filetree/module'
import { types as jklTypes } from './protos/jackal-dao/canine/jackaldao.canine.jklmint/module'
// import { types as lpTypes } from './protos/jackal-dao/canine/jackaldao.canine.lp/module'
import { types as notificationTypes } from './protos/jackal-dao/canine/jackaldao.canine.notifications/module'
import { types as rnsTypes } from './protos/jackal-dao/canine/jackaldao.canine.rns/module'
import { types as storageTypes } from './protos/jackal-dao/canine/jackaldao.canine.storage/module'
import fileTreeTypes from '@/snackages/tx/custom/fileTree'
import rnsTypes from '@/snackages/tx/custom/rns'
import storageTypes from '@/snackages/tx/custom/storage'

/**
* Jackal Stock CosmosSDK Protos
*/
import { types as bankTypes } from './protos/cosmos/cosmos-sdk/cosmos.bank.v1beta1/module'
import { types as distributionTypes } from './protos/cosmos/cosmos-sdk/cosmos.distribution.v1beta1/module'
import { types as govTypes } from './protos/cosmos/cosmos-sdk/cosmos.gov.v1beta1/module'
import { types as stakingTypes } from './protos/cosmos/cosmos-sdk/cosmos.staking.v1beta1/module'
import bankTypes from '@/snackages/tx/static/bank'
import distributionTypes from '@/snackages/tx/static/distribution'
import govTypes from '@/snackages/tx/static/gov'
import stakingTypes from '@/snackages/tx/static/staking'

/**
* Interfaces
*/
interface TxClientOptions {
addr: string
}
interface SignAndBroadcastOptions {
export interface SignAndBroadcastOptions {
fee: StdFee,
memo?: string
}
export type TMasterBroadcaster = (msgs: EncodeObject[], options: SignAndBroadcastOptions) => Promise<DeliverTxResponse>
export interface IGenBroadcaster {
masterBroadcaster: TMasterBroadcaster
}

/**
* The Magic
*/
const masterTypes = [
...cosmTypes,
...dsigTypes,
...filetreeTypes,
...jklTypes,
// ...lpTypes,
...notificationTypes,
...rnsTypes,
...storageTypes,
...bankTypes,
...distributionTypes,
...govTypes,
...stakingTypes
...Object.values(fileTreeTypes),
...Object.values(rnsTypes),
...Object.values(storageTypes),
...Object.values(bankTypes),
...Object.values(distributionTypes),
...Object.values(govTypes),
...Object.values(stakingTypes)
]
const registry = new Registry(<any>masterTypes)
const defaultFee = {
amount: [],
gas: '200000',
}

const genBroadcaster = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions = { addr: 'http://localhost:26657' }) => {
const genBroadcaster = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions = { addr: 'http://localhost:26657' }): Promise<IGenBroadcaster> => {
if (!wallet) throw new Error('wallet is required')
const client = await SigningStargateClient.connectWithSigner(addr, wallet, { registry })
const { address } = (await wallet.getAccounts())[0]
Expand Down
206 changes: 163 additions & 43 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,163 @@
/**
* Jackal Custom Protos
*/

export { genBroadcaster as makeMasterBroadcaster } from './customBroadcast'

/**
* Jackal Custom Protos
*/

export { txClient as dsigTxClient, queryClient as dsigQueryClient } from './protos/jackal-dao/canine/jackaldao.canine.dsig/module'
export { txClient as filetreeTxClient, queryClient as filetreeQueryClient } from './protos/jackal-dao/canine/jackaldao.canine.filetree/module'
export { txClient as jklMintTxClient, queryClient as jklMintQueryClient } from './protos/jackal-dao/canine/jackaldao.canine.jklmint/module'
// export { txClient as lpTxClient, queryClient as lpQueryClient } from './protos/jackal-dao/canine/jackaldao.canine.lp/module'
export { txClient as notificationTxClient, queryClient as notificationQueryClient } from './protos/jackal-dao/canine/jackaldao.canine.notifications/module'
export { txClient as rnsTxClient, queryClient as rnsQueryClient } from './protos/jackal-dao/canine/jackaldao.canine.rns/module'
export { txClient as storageTxClient, queryClient as storageQueryClient } from './protos/jackal-dao/canine/jackaldao.canine.storage/module'

export { Api as dsigQueryApi } from './protos/jackal-dao/canine/jackaldao.canine.dsig/module/rest'
export { Api as filetreeQueryApi } from './protos/jackal-dao/canine/jackaldao.canine.filetree/module/rest'
export { Api as jklMintQueryApi } from './protos/jackal-dao/canine/jackaldao.canine.jklmint/module/rest'
// export { Api as lpQueryApi } from './protos/jackal-dao/canine/jackaldao.canine.lp/module/rest'
export { Api as notificationQueryApi } from './protos/jackal-dao/canine/jackaldao.canine.notifications/module/rest'
export { Api as rnsQueryApi } from './protos/jackal-dao/canine/jackaldao.canine.rns/module/rest'
export { Api as storageQueryApi } from './protos/jackal-dao/canine/jackaldao.canine.storage/module/rest'

/**
* Jackal Stock CosmosSDK Protos
*/

export { txClient as cosmTxClient, queryClient as cosmQueryClient } from './protos/CosmWasm/wasmd/cosmwasm.wasm.v1/module'

export { txClient as bankTxClient, queryClient as bankQueryClient } from './protos/cosmos/cosmos-sdk/cosmos.bank.v1beta1/module'
export { txClient as distributionTxClient, queryClient as distributionQueryClient } from './protos/cosmos/cosmos-sdk/cosmos.distribution.v1beta1/module'
export { txClient as govTxClient, queryClient as govQueryClient } from './protos/cosmos/cosmos-sdk/cosmos.gov.v1beta1/module'
export { txClient as stakingTxClient, queryClient as stakingQueryClient } from './protos/cosmos/cosmos-sdk/cosmos.staking.v1beta1/module'

export { Api as cosmQueryApi } from './protos/CosmWasm/wasmd/cosmwasm.wasm.v1/module/rest'

export { Api as bankQueryApi } from './protos/cosmos/cosmos-sdk/cosmos.bank.v1beta1/module/rest'
export { Api as distributionQueryApi } from './protos/cosmos/cosmos-sdk/cosmos.distribution.v1beta1/module/rest'
export { Api as govQueryApi } from './protos/cosmos/cosmos-sdk/cosmos.gov.v1beta1/module/rest'
export { Api as stakingQueryApi } from './protos/cosmos/cosmos-sdk/cosmos.staking.v1beta1/module/rest'
import { OfflineSigner } from '@cosmjs/proto-signing'
import { genBroadcaster, IGenBroadcaster, TMasterBroadcaster } from '@/customBroadcast'
import IProtoBuilder from '@/interfaces/classes/IProtoBuilder'
import IQueryFileTree from '@/interfaces/classes/IQueryFileTree'
import IQueryJklMint from '@/interfaces/classes/IQueryJklMint'
import IQueryRns from '@/interfaces/classes/IQueryRns'
import IQueryStorage from '@/interfaces/classes/IQueryStorage'
import IQueryBank from '@/interfaces/classes/IQueryBank'
import IQueryDistribution from '@/interfaces/classes/IQueryDistribution'
import IQueryGov from '@/interfaces/classes/IQueryGov'
import IQueryStaking from '@/interfaces/classes/IQueryStaking'
import {
GrpcWebImpl,
IFileTreeGrpc,
IJklMintGrpc,
IRnsGrpc,
IStorageGrpc,
IBankGrpc,
IDistributionGrpc,
IGovGrpc,
IStakingGrpc,
TGrpc
} from '@/interfaces/IGrpcWebImpl'

import QueryFileTree from '@/snackages/query/custom/fileTree'
import QueryJklMint from '@/snackages/query/custom/jklMint'
import QueryRns from '@/snackages/query/custom/rns'
import QueryStorage from '@/snackages/query/custom/storage'
import QueryBank from '@/snackages/query/static/bank'
import QueryDistribution from '@/snackages/query/static/distribution'
import QueryGov from '@/snackages/query/static/gov'
import QueryStaking from '@/snackages/query/static/staking'

import { ITxFileTree, TxFileTree } from '@/snackages/tx/custom/fileTree'
import { ITxRns, TxRns } from '@/snackages/tx/custom/rns'
import { ITxStorage, TxStorage } from '@/snackages/tx/custom/storage'
import { ITxBank, TxBank } from '@/snackages/tx/static/bank'
import { ITxDistribution, TxDistribution } from '@/snackages/tx/static/distribution'
import { ITxGov, TxGov } from '@/snackages/tx/static/gov'
import { ITxStaking, TxStaking } from '@/snackages/tx/static/staking'
import IAllQuery from '@/interfaces/IAllQuery'
import IAllTx from '@/interfaces/IAllTx'

export default class ProtoBuilder implements IProtoBuilder {
private readonly signer: OfflineSigner
private readonly txUrl: string
private readonly GRpc: TGrpc

constructor (signer: OfflineSigner, txUrl?: string, queryUrl?: string) {
const qUrl = queryUrl || 'http://localhost:9091'
this.signer = signer
this.txUrl = txUrl || 'http://localhost:26657'
this.GRpc = new GrpcWebImpl(qUrl, {})
}

/** General */
makeMasterBroadcaster (): Promise<IGenBroadcaster> {
return genBroadcaster(this.signer, { addr: this.txUrl })
}
makeAllQuery (): IAllQuery {
return {
/** Custom */
fileTree: this.makeFileTreeQuery(),
jklMint: this.makeJklMintQuery(),
rns: this.makeRnsQuery(),
storage: this.makeStorageQuery(),
/** Static */
bank: this.makeBankQuery(),
distribution: this.makeDistributionQuery(),
gov: this.makeGovQuery(),
staking: this.makeStakingQuery()
}
}
makeAllTx (): IAllTx {
return {
/** Custom */
fileTree: this.makeFileTreeTx(),
jklMint: null,
rns: this.makeRnsTx(),
storage: this.makeStorageTx(),
/** Static */
bank: this.makeBankTx(),
distribution: this.makeDistributionTx(),
gov: this.makeGovTx(),
staking: this.makeStakingTx()
}
}

/** Custom */
makeFileTreeQuery (): IQueryFileTree {
return new QueryFileTree(this.GRpc as IFileTreeGrpc)
}
makeFileTreeTx (): ITxFileTree {
return new TxFileTree()
}
makeJklMintQuery (): IQueryJklMint {
return new QueryJklMint(this.GRpc as IJklMintGrpc)
}
makeRnsQuery (): IQueryRns {
return new QueryRns(this.GRpc as IRnsGrpc)
}
makeRnsTx (): ITxRns {
return new TxRns()
}
makeStorageQuery (): IQueryStorage {
return new QueryStorage(this.GRpc as IStorageGrpc)
}
makeStorageTx (): ITxStorage {
return new TxStorage()
}

/** Static */
makeBankQuery (): IQueryBank {
return new QueryBank(this.GRpc as IBankGrpc)
}
makeBankTx (): ITxBank {
return new TxBank()
}
makeDistributionQuery (): IQueryDistribution {
return new QueryDistribution(this.GRpc as IDistributionGrpc)
}
makeDistributionTx (): ITxDistribution {
return new TxDistribution()
}
makeGovQuery (): IQueryGov {
return new QueryGov(this.GRpc as IGovGrpc)
}
makeGovTx (): ITxGov {
return new TxGov()
}
makeStakingQuery (): IQueryStaking {
return new QueryStaking(this.GRpc as IStakingGrpc)
}
makeStakingTx (): ITxStaking {
return new TxStaking()
}
}

export {
/** General */
IAllQuery,
IAllTx,
IGenBroadcaster,
IProtoBuilder,
TMasterBroadcaster,

/** Custom */
IQueryJklMint,
IQueryRns,
ITxRns,
IQueryStorage,
ITxStorage,

/** Static */
IQueryBank,
ITxBank,
IQueryDistribution,
ITxDistribution,
IQueryGov,
ITxGov,
IQueryStaking,
ITxStaking
}
Loading

0 comments on commit c478ccc

Please sign in to comment.