-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add_get_first_address_in_smart_contract_library_#740
- Loading branch information
1 parent
e1cf03d
commit a6bce72
Showing
14 changed files
with
568 additions
and
38 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
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,45 @@ | ||
defmodule Archethic.P2P.Message.FirstTransactionAddress do | ||
@moduledoc false | ||
alias Archethic.Utils | ||
@enforce_keys [:address] | ||
defstruct [:address] | ||
|
||
@type t() :: %__MODULE__{ | ||
address: binary() | ||
} | ||
|
||
@doc """ | ||
Serialize FirstTransactionAddress Struct | ||
iex> %FirstTransactionAddress{ | ||
...> address: <<0, 0, 94, 5, 249, 103, 126, 31, 43, 57, 25, 14, 187, 133, 59, 234, 201, 172, | ||
...> 3, 195, 43, 81, 81, 146, 164, 202, 147, 218, 207, 204, 31, 185, 73, 251>> | ||
...> } |> FirstTransactionAddress.serialize() | ||
#address | ||
<<0, 0, 94, 5, 249, 103, 126, 31, 43, 57, 25, 14, 187, 133, 59, 234, 201, 172, | ||
3, 195, 43, 81, 81, 146, 164, 202, 147, 218, 207, 204, 31, 185, 73, 251>> | ||
""" | ||
def serialize(%__MODULE__{address: address}) do | ||
<<address::binary>> | ||
end | ||
|
||
@doc """ | ||
DeSerialize FirstTransactionAddress Struct | ||
iex> # First address | ||
...> <<0, 0, 94, 5, 249, 103, 126, 31, 43, 57, 25, 14, 187, 133, 59, 234, 201, 172, | ||
...> 3, 195, 43, 81, 81, 146, 164, 202, 147, 218, 207, 204, 31, 185, 73, 251>> | ||
...> |> FirstTransactionAddress.deserialize() | ||
{ | ||
%FirstTransactionAddress{ | ||
address: <<0, 0, 94, 5, 249, 103, 126, 31, 43, 57, 25, 14, 187, 133, 59, 234, 201, 172, | ||
3, 195, 43, 81, 81, 146, 164, 202, 147, 218, 207, 204, 31, 185, 73, 251>> | ||
}, ""} | ||
""" | ||
def deserialize(bin) do | ||
{address, <<rest::bitstring>>} = Utils.deserialize_address(bin) | ||
|
||
{%__MODULE__{address: address}, rest} | ||
end | ||
end |
65 changes: 65 additions & 0 deletions
65
lib/archethic/p2p/message/get_first_transaction_address.ex
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,65 @@ | ||
defmodule Archethic.P2P.Message.GetFirstTransactionAddress do | ||
@moduledoc """ | ||
Represents a message to request the first address from a transaction chain. | ||
Genesis address != first transaction address | ||
Hash of current index public key gives current index address | ||
Hash of genesis public key gives genesis address | ||
Hash of first public key gives first transaction address | ||
""" | ||
alias Archethic.Utils | ||
alias Archethic.P2P.Message.FirstTransactionAddress | ||
alias Archethic.TransactionChain | ||
alias Archethic.P2P.Message.NotFound | ||
|
||
@enforce_keys [:address] | ||
defstruct [:address] | ||
|
||
@type t() :: %__MODULE__{ | ||
address: binary() | ||
} | ||
|
||
@doc """ | ||
Serialize GetFirstTransactionAddress Struct | ||
iex> %GetFirstTransactionAddress{ | ||
...> address: <<0, 0, 94, 5, 249, 103, 126, 31, 43, 57, 25, 14, 187, 133, 59, 234, 201, 172, | ||
...> 3, 195, 43, 81, 81, 146, 164, 202, 147, 218, 207, 204, 31, 185, 73, 251>> | ||
...> } |> GetFirstTransactionAddress.serialize() | ||
#address | ||
<<0, 0, 94, 5, 249, 103, 126, 31, 43, 57, 25, 14, 187, 133, 59, 234, 201, 172, | ||
3, 195, 43, 81, 81, 146, 164, 202, 147, 218, 207, 204, 31, 185, 73, 251>> | ||
""" | ||
def serialize(%__MODULE__{address: address}) do | ||
<<address::binary>> | ||
end | ||
|
||
@doc """ | ||
DeSerialize GetFirstTransactionAddress Struct | ||
iex> # First address | ||
...> <<0, 0, 94, 5, 249, 103, 126, 31, 43, 57, 25, 14, 187, 133, 59, 234, 201, 172, | ||
...> 3, 195, 43, 81, 81, 146, 164, 202, 147, 218, 207, 204, 31, 185, 73, 251>> | ||
...> |> GetFirstTransactionAddress.deserialize() | ||
{ | ||
%GetFirstTransactionAddress{ | ||
address: <<0, 0, 94, 5, 249, 103, 126, 31, 43, 57, 25, 14, 187, 133, 59, 234, 201, 172, | ||
3, 195, 43, 81, 81, 146, 164, 202, 147, 218, 207, 204, 31, 185, 73, 251>> | ||
}, ""} | ||
""" | ||
def deserialize(bin) do | ||
{address, <<rest::bitstring>>} = Utils.deserialize_address(bin) | ||
|
||
{%__MODULE__{address: address}, rest} | ||
end | ||
|
||
def process(%__MODULE__{address: address}) do | ||
case TransactionChain.get_first_transaction_address(address) do | ||
{:error, :transaction_not_exists} -> | ||
%NotFound{} | ||
|
||
{:ok, first_address} -> | ||
%FirstTransactionAddress{address: first_address} | ||
end | ||
end | ||
end |
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
Oops, something went wrong.