Tradehub.Tx (Tradehub v0.1.13) View Source
Use this module to broadcast your messages into the Tradehub blockchain.
The steps of broadcasting messages describes as below:
- Compose your messages
- Construct signing messages
- Sign the signing messages with your private key
- Construct tx
- Construct completeTx
Examples
iex> import Tradehub.Tx
iex> wallet = Tradehub.Wallet.from_mnemonic! Application.fetch_env!(:tradehub, :wallet)
iex> message =
...> %{
...> username: "trade",
...> twitter: "mvanh91",
...> originator: wallet.address
...> }
...> |> Tradehub.Tx.UpdateProfile.compose!()
iex> {wallet, [message]}
...> |> generate_signing_message()
...> |> sign()
...> |> construct_tx()
...> |> build_tx()
...> |> Jason.encode!()
...> |> Tradehub.send
Or
iex> import Tradehub.Tx
iex> wallet = Tradehub.Wallet.from_mnemonic! Application.fetch_env!(:tradehub, :wallet)
iex> message =
...> %{
...> username: "trade",
...> twitter: "mvanh91",
...> originator: wallet.address
...> }
...> |> Tradehub.Tx.UpdateProfile.compose!()
iex> broadcast([message], wallet)
Link to this section Summary
Types
Wrapped transaction with the network fee, and mode
The fee you might have to spend to broadcast the message
The payload that actually broadcast across over the blockchain. It is then used to form the signing message.
Signature for a signing message
Signing message
Transaction
Functions
Wrap the transaction with the network fee
Construct the transaction.
This is the first step of buiding a transaction. It purposes is to fetch the information of the given wallet and generate a signing message that contains information about account number, chain id, and the fee you might have to spend for handling messages once it broadcasted to the blockchain.
Sign the signing message with the wallet private key.
Link to this section Types
Specs
Wrapped transaction with the network fee, and mode
Specs
fee() :: %{amount: [Tradehub.amount()], gas: String.t()}
The fee you might have to spend to broadcast the message
Specs
The payload that actually broadcast across over the blockchain. It is then used to form the signing message.
Specs
signature() :: %{ pub_key: pub_key :: %{type: String.t(), value: String.t()}, signature: String.t() }
Signature for a signing message
Specs
signing_message() :: %{ account_number: String.t(), chain_id: String.t(), fee: fee(), memo: String.t(), msgs: [message()], sequence: String.t() }
Signing message
Specs
Transaction
Link to this section Functions
Specs
broadcast([message()], Tradehub.Wallet.t(), String.t()) :: any()
Specs
Wrap the transaction with the network fee
Specs
Construct the transaction.
Specs
generate_signing_message({Tradehub.Wallet.t(), [message()]}) :: tuple()
This is the first step of buiding a transaction. It purposes is to fetch the information of the given wallet and generate a signing message that contains information about account number, chain id, and the fee you might have to spend for handling messages once it broadcasted to the blockchain.
Specs
sign({Tradehub.Wallet.t(), [message()], signing_message()}) :: {[message()], signature()}
Sign the signing message with the wallet private key.