-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
makeTx
function with NetworkProvider
interface
Related to #2617 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/planetarium/lib9c/issues/2617?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Account, Address } from '@planetarium/account'; | ||
import { UnsignedTx } from '@planetarium/tx'; | ||
import { PolymorphicAction } from './actions/common.js'; | ||
|
||
export interface NetworkProvider { | ||
getNextNonce(address: Address): Promise<bigint>; | ||
getGenesisHash(): Promise<string>; | ||
} | ||
|
||
export async function makeTx( | ||
account: Account, | ||
provider: NetworkProvider, | ||
action: PolymorphicAction | ||
): Promise<UnsignedTx> { | ||
const nonce = await provider.getNextNonce(account.address); | ||
const genesisHash = await provider.getGenesisHash(); | ||
|
||
return new UnsignedTx({ | ||
nonce, | ||
genesisHash, | ||
signer: account, | ||
actions: [action], | ||
}); | ||
} |