Tradehub.Tx (Tradehub v0.1.17) View Source

Use this module to broadcast your messages into the Tradehub blockchain.

The steps of broadcasting messages describes as below:

  1. Compose your messages
  2. Construct signing messages
  3. Sign the signing messages with your private key
  4. Construct tx
  5. 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

complete_tx() :: %{fee: fee(), mode: String.t(), tx: tx()}

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

message() :: %{type: String.t(), value: map()}

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

tx() :: %{
  fee: fee(),
  msg: [message()],
  signature: [signature()],
  memo: String.t()
}

Transaction

Link to this section Functions

Link to this function

broadcast(messages, wallet, memo \\ "")

View Source

Specs

broadcast([message()], Tradehub.Wallet.t(), String.t()) :: any()
Link to this function

build_tx(tx, mode \\ :block)

View Source

Specs

build_tx(any(), atom()) :: %{mode: binary(), tx: any()}

Wrap the transaction with the network fee

Link to this function

construct_tx(arg, memo \\ "")

View Source

Specs

construct_tx({[message()], signature()}, String.t()) :: any()

Construct the transaction.

Link to this function

generate_signing_message(arg)

View Source

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 the signing message with the wallet private key.