-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,743 additions
and
213 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
export const ROUTE = "background-tx"; |
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 @@ | ||
export * from "./messages"; |
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,78 @@ | ||
import { Message, MessageSender } from "../../common/message"; | ||
import { ROUTE } from "./constants"; | ||
|
||
export class RequestBackgroundTxMsg extends Message<{}> { | ||
public static type() { | ||
return "request-background-tx"; | ||
} | ||
|
||
/** | ||
* @param chainId Chain id | ||
* @param txBytes Hex encoded bytes for tx | ||
* @param mode Broadcast mode | ||
*/ | ||
public static create( | ||
chainId: string, | ||
txBytes: string, | ||
mode: "sync" | "async" | "commit" = "commit", | ||
origin: string | ||
): RequestBackgroundTxMsg { | ||
const msg = new RequestBackgroundTxMsg(); | ||
msg.chainId = chainId; | ||
msg.txBytes = txBytes; | ||
msg.mode = mode; | ||
msg.origin = origin; | ||
return msg; | ||
} | ||
|
||
public chainId: string = ""; | ||
public txBytes: string = ""; | ||
public mode?: "sync" | "async" | "commit"; | ||
public origin: string = ""; | ||
|
||
validateBasic(): void { | ||
if (!this.chainId) { | ||
throw new Error("chain id is empty"); | ||
} | ||
|
||
if (!this.txBytes) { | ||
throw new Error("tx bytes is empty"); | ||
} | ||
|
||
if ( | ||
!this.mode || | ||
(this.mode !== "sync" && this.mode !== "async" && this.mode !== "commit") | ||
) { | ||
throw new Error("invalid mode"); | ||
} | ||
} | ||
|
||
// Approve external approves sending message if they submit their origin correctly. | ||
// Keeper or handler must check that this origin has right permission. | ||
approveExternal(sender: MessageSender): boolean { | ||
const isInternal = super.approveExternal(sender); | ||
if (isInternal) { | ||
return true; | ||
} | ||
|
||
// TODO: When is a url undefined? | ||
if (!sender.url) { | ||
throw new Error("url is empty"); | ||
} | ||
|
||
if (!this.origin) { | ||
throw new Error("origin is empty"); | ||
} | ||
|
||
const url = new URL(sender.url); | ||
return url.origin === this.origin; | ||
} | ||
|
||
route(): string { | ||
return ROUTE; | ||
} | ||
|
||
type(): string { | ||
return RequestBackgroundTxMsg.type(); | ||
} | ||
} |
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,14 @@ | ||
import { Bech32Config } from "@everett-protocol/cosmosjs/core/bech32Config"; | ||
|
||
export interface ChainInfo { | ||
readonly rpc: string; | ||
readonly rest: string; | ||
readonly chainId: string; | ||
readonly chainName: string; | ||
readonly nativeCurrency: { | ||
coinDenom: string; | ||
coinMinimalDenom: string; | ||
coinDecimals: number; | ||
}; | ||
readonly bech32Config: Bech32Config; | ||
} |
Oops, something went wrong.