diff --git a/lib/archethic/beacon_chain/replication_attestation.ex b/lib/archethic/beacon_chain/replication_attestation.ex index 8d543b94a..aca94b054 100644 --- a/lib/archethic/beacon_chain/replication_attestation.ex +++ b/lib/archethic/beacon_chain/replication_attestation.ex @@ -37,7 +37,9 @@ defmodule Archethic.BeaconChain.ReplicationAttestation do ...> 200, 170, 241, 23, 249, 75, 17, 23, 241, 185, 36, 15, 66>>, ...> type: :transfer, ...> timestamp: ~U[2022-01-27 09:14:22Z], - ...> fee: 10_000_000 + ...> fee: 10_000_000, + ...> validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> ...> }, ...> confirmations: [ ...> { @@ -52,6 +54,8 @@ defmodule Archethic.BeaconChain.ReplicationAttestation do << # Version 1, + # Transaction summary version + 1, # Tx address 0, 0, 232, 183, 247, 15, 195, 209, 138, 58, 226, 218, 221, 135, 181, 43, 216, 164, 4, 187, 38, 200, 170, 241, 23, 249, 75, 17, 23, 241, 185, 36, 15, 66, @@ -63,6 +67,9 @@ defmodule Archethic.BeaconChain.ReplicationAttestation do 0, 0, 0, 0, 0, 152, 150, 128, # Nb movements 1, 0, + # Validation stamp checksum + 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219, # Nb confirmations 1, # Replication node position @@ -98,10 +105,12 @@ defmodule Archethic.BeaconChain.ReplicationAttestation do ## Examples - iex> <<1, 0, 0, 232, 183, 247, 15, 195, 209, 138, 58, 226, 218, 221, 135, 181, 43, 216, + iex> <<1, 1, 0, 0, 232, 183, 247, 15, 195, 209, 138, 58, 226, 218, 221, 135, 181, 43, 216, ...> 164, 4, 187, 38, 200, 170, 241, 23, 249, 75, 17, 23, 241, 185, 36, 15, 66, ...> 0, 0, 1, 126, 154, 208, 125, 176, ...> 253, 0, 0, 0, 0, 0, 152, 150, 128, 1, 0, + ...> 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219, ...> 1, 0,64, ...> 129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217, ...> 100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138, @@ -116,7 +125,9 @@ defmodule Archethic.BeaconChain.ReplicationAttestation do 200, 170, 241, 23, 249, 75, 17, 23, 241, 185, 36, 15, 66>>, type: :transfer, timestamp: ~U[2022-01-27 09:14:22.000Z], - fee: 10_000_000 + fee: 10_000_000, + validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> }, confirmations: [ { diff --git a/lib/archethic/beacon_chain/slot.ex b/lib/archethic/beacon_chain/slot.ex index eba272c99..5087a47bd 100644 --- a/lib/archethic/beacon_chain/slot.ex +++ b/lib/archethic/beacon_chain/slot.ex @@ -369,7 +369,9 @@ defmodule Archethic.BeaconChain.Slot do ...> timestamp: ~U[2020-06-25 15:11:53Z], ...> type: :transfer, ...> movements_addresses: [], - ...> fee: 10_000_000 + ...> fee: 10_000_000, + ...> validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> ...> }, ...> confirmations: [{0, <<129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217, ...> 100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138, @@ -401,6 +403,8 @@ defmodule Archethic.BeaconChain.Slot do 1, 1, # Attestation version 1, + # Transaction summary version + 1, # Address 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, @@ -412,6 +416,9 @@ defmodule Archethic.BeaconChain.Slot do 0, 0, 0, 0, 0, 152, 150, 128, # Nb movements addresses 1, 0, + # Validation stamp checksum + 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219, # Nb confirmations 1, # Replication node position @@ -483,16 +490,16 @@ defmodule Archethic.BeaconChain.Slot do ## Examples - iex> <<1, 0, 96, 8, 1, 120, 1, 1, 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, - ...> 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, - ...> 206, 162, 233, 28, 49, 204, 255, 12, 0, 0, 1, 114, 236, 9, 2, 168, 253, 0, 0, 0, - ...> 0, 0, 152, 150, 128, 1, 0, 1, 0, 64, 129, 204, 107, 81, 235, 88, 234, 207, - ...> 125, 1, 208, 227, 239, 175, 78, 217, 100, 172, 67, 228, 131, 42, 177, 200, 54, - ...> 225, 34, 241, 35, 226, 108, 138, 201, 2, 32, 75, 92, 49, 194, 42, 113, 154, 20, - ...> 43, 216, 176, 11, 159, 188, 119, 6, 8, 48, 201, 244, 138, 99, 52, 22, 1, 97, 123, - ...> 140, 195, 1, 1, 0, 0, 38, 105, 235, 147, 234, 114, 41, 1, 152, 148, 120, 31, 200, - ...> 255, 174, 190, 91, 100, 169, 225, 113, 249, 125, 21, 168, 14, 196, 222, 140, 87, - ...> 143, 241, 94, 244, 190, 185, 0, 2, 600::16, 356::16, 10, 0 >> + iex> <<1, 0, 96, 8, 1, 120, 1, 1, 1, 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, 0, 0, 1, 114, 236, 9, 2, 168, 253, + ...> 0, 0, 0, 0, 0, 152, 150, 128, 1, 0, 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219, 1, 0, 64, + ...> 129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217, + ...> 100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138, + ...> 201, 2, 32, 75, 92, 49, 194, 42, 113, 154, 20, 43, 216, 176, 11, 159, 188, + ...> 119, 6, 8, 48, 201, 244, 138, 99, 52, 22, 1, 97, 123, 140, 195, 1, 1, + ...> 0, 0, 38, 105, 235, 147, 234, 114, 41, 1, 152, 148, 120, 31, 200, 255, 174, 190, 91, + ...> 100, 169, 225, 113, 249, 125, 21, 168, 14, 196, 222, 140, 87, 143, 241, 94, 244, 190, 185, 0, 2, 600::16, 356::16, 10, 0>> ...> |> Slot.deserialize() { %Slot{ @@ -507,7 +514,9 @@ defmodule Archethic.BeaconChain.Slot do timestamp: ~U[2020-06-25 15:11:53.000Z], type: :transfer, movements_addresses: [], - fee: 10_000_000 + fee: 10_000_000, + validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> }, confirmations: [{0, <<129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217, 100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138, diff --git a/lib/archethic/beacon_chain/summary.ex b/lib/archethic/beacon_chain/summary.ex index a8d408686..9936a69c8 100644 --- a/lib/archethic/beacon_chain/summary.ex +++ b/lib/archethic/beacon_chain/summary.ex @@ -358,7 +358,9 @@ defmodule Archethic.BeaconChain.Summary do ...> timestamp: ~U[2020-06-25 15:11:53Z], ...> type: :transfer, ...> movements_addresses: [], - ...> fee: 10_000_000 + ...> fee: 10_000_000, + ...> validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> ...> }, ...> confirmations: [{0, <<255, 120, 232, 52, 141, 15, 97, 213, 231, 93, 242, 160, 123, 25, 192, 3, 133, ...> 170, 197, 102, 148, 208, 119, 130, 225, 102, 130, 96, 223, 61, 36, 76, 229, @@ -383,6 +385,8 @@ defmodule Archethic.BeaconChain.Summary do 1, 1, # Replication attestation version 1, + # Transaction summary version + 1, # Transaction address 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, @@ -394,6 +398,9 @@ defmodule Archethic.BeaconChain.Summary do 0, 0, 0, 0, 0, 152, 150, 128, # Nb movement addresses 1, 0, + # Validation stamp checksum + 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219, # Nb confirmations 1, # Replication storage node position @@ -463,15 +470,16 @@ defmodule Archethic.BeaconChain.Summary do ## Examples - iex> <<1, 0, 96, 7, 114, 128, 1, 1, 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, - ...> 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, - ...> 206, 162, 233, 28, 49, 204, 255, 12, 0, 0, 1, 114, 236, 9, 2, 168, 253, 0, 0, - ...> 0, 0, 0, 152, 150, 128, 1, 0, 1, 0, 64, 255, 120, 232, 52, 141, 15, 97, 213, 231, 93, 242, 160, 123, 25, 192, 3, 133, + iex> << 1, 0, 96, 7, 114, 128, 1, 1, 1, 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, 0, 0, 1, 114, 236, 9, 2, 168, + ...> 253, 0, 0, 0, 0, 0, 152, 150, 128, 1, 0, 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219, 1, 0, 64, + ...> 255, 120, 232, 52, 141, 15, 97, 213, 231, 93, 242, 160, 123, 25, 192, 3, 133, ...> 170, 197, 102, 148, 208, 119, 130, 225, 102, 130, 96, 223, 61, 36, 76, 229, ...> 210, 5, 142, 79, 249, 177, 51, 15, 45, 45, 141, 217, 85, 77, 146, 199, 126, - ...> 213, 205, 108, 164, 167, 112, 201, 194, 113, 133, 242, 104, 254, 253, - ...> 0, 2, 1::1, 1::1, 100, 100, 1, 1, 0, 1, 190, 20, 188, 141, 156, 135, 91, 37, 96, 187, 27, 24, 41, 130, 118, - ...> 93, 43, 240, 229, 97, 227, 194, 31, 97, 228, 78, 156, 194, 154, 74, 160, 104, 3, 132>> + ...> 213, 205, 108, 164, 167, 112, 201, 194, 113, 133, 242, 104, 254, 253, 0, 2, 1::1, 1::1, 100, 100, 1, 1, + ...> 0, 1, 190, 20, 188, 141, 156, 135, 91, 37, 96, 187, 27, 24, 41, 130, 118, + ...> 93, 43, 240, 229, 97, 227, 194, 31, 97, 228, 78, 156, 194, 154, 74, 160, 104, 3, 132 >> ...> |> Summary.deserialize() { %Summary{ @@ -486,7 +494,9 @@ defmodule Archethic.BeaconChain.Summary do timestamp: ~U[2020-06-25 15:11:53.000Z], type: :transfer, movements_addresses: [], - fee: 10_000_000 + fee: 10_000_000, + validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> }, confirmations: [{0, <<255, 120, 232, 52, 141, 15, 97, 213, 231, 93, 242, 160, 123, 25, 192, 3, 133, 170, 197, 102, 148, 208, 119, 130, 225, 102, 130, 96, 223, 61, 36, 76, 229, diff --git a/lib/archethic/beacon_chain/summary_aggregate.ex b/lib/archethic/beacon_chain/summary_aggregate.ex index b1141dad1..0d4f1ef4f 100644 --- a/lib/archethic/beacon_chain/summary_aggregate.ex +++ b/lib/archethic/beacon_chain/summary_aggregate.ex @@ -212,7 +212,9 @@ defmodule Archethic.BeaconChain.SummaryAggregate do ...> 249, 138, 85, 71, 127, 190, 20, 186, 69, 131, 97, 194, 30, 71, 116>>, ...> type: :transfer, ...> timestamp: ~U[2022-02-01 10:00:00.204Z], - ...> fee: 10_000_000 + ...> fee: 10_000_000, + ...> validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> ...> }, ...> confirmations: [ ...> { @@ -246,6 +248,8 @@ defmodule Archethic.BeaconChain.SummaryAggregate do 1, 1, # Replication attestations version 1, + # Transaction summary version + 1, # Address 0, 0, 120, 123, 229, 13, 144, 130, 230, 18, 17, 45, 244, 92, 226, 107, 11, 104, 226, 249, 138, 85, 71, 127, 190, 20, 186, 69, 131, 97, 194, 30, 71, 116, @@ -257,6 +261,9 @@ defmodule Archethic.BeaconChain.SummaryAggregate do 0, 0, 0, 0, 0, 152, 150, 128, # Nb movements addresses 1, 0, + # Validation stamp checksum + 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219, # Nb confirmations 1, # Replication node position @@ -336,14 +343,17 @@ defmodule Archethic.BeaconChain.SummaryAggregate do ## Examples - iex> SummaryAggregate.deserialize(<<1, 98, 29, 98, 0, 1, 1, 1, 0, 0, 120, 123, 229, 13, 144, 130, 230, - ...> 18, 17, 45, 244, 92, 226, 107, 11, 104, 226, 249, 138, 85, 71, 127, 190, 20, 186, 69, 131, 97, 194, - ...> 30, 71, 116, 0, 0, 1, 126, 180, 186, 17, 204, 253, 0, 0, 0, 0, 0, 152, 150, 128, 1, 0, 1, 0, 64, - ...> 129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217, 100, 172, 67, 228, 131, - ...> 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138, 201, 2, 32, 75, 92, 49, 194, 42, 113, 154, 20, - ...> 43, 216, 176, 11, 159, 188, 119, 6, 8, 48, 201, 244, 138, 99, 52, 22, 1, 97, 123, 140, 195, 1, 0, 1, - ...> 3, 1::1, 0::1, 1::1, 50, 70, 80, 1, 1, 0, 1, 57, 98, 198, 202, 155, 43, 217, 149, 5, 213, 109, 252, - ...> 111, 87, 231, 170, 54, 211, 178, 208, 5, 184, 33, 193, 167, 91, 160, 131, 129, 117, 45, 242, 3, 132>>) + iex> SummaryAggregate.deserialize(<<1, 98, 29, 98, 0, 1, 1, 1, 1, 0, 0, 120, 123, 229, 13, 144, + ...> 130, 230, 18, 17, 45, 244, 92, 226, 107, 11, 104, 226, 249, 138, 85, 71, 127, 190, 20, 186, 69, + ...> 131, 97, 194, 30, 71, 116, 0, 0, 1, 126, 180, 186, 17, 204, 253, 0, 0, 0, 0, 0, 152, 150, 128, + ...> 1, 0, 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219, 1, 0, 64, + ...> 129, 204, 107, 81, 235, 88, 234, 207, 125, 1, 208, 227, 239, 175, 78, 217, + ...> 100, 172, 67, 228, 131, 42, 177, 200, 54, 225, 34, 241, 35, 226, 108, 138, + ...> 201, 2, 32, 75, 92, 49, 194, 42, 113, 154, 20, 43, 216, 176, 11, 159, 188, + ...> 119, 6, 8, 48, 201, 244, 138, 99, 52, 22, 1, 97, 123, 140, 195, 1, 0, 1, 3, 1::1, 0::1, 1::1, + ...> 50, 70, 80, 1, 1, 0, 1, 57, 98, 198, 202, 155, 43, 217, 149, 5, 213, 109, 252, 111, 87, 231, 170, 54, + ...> 211, 178, 208, 5, 184, 33, 193, 167, 91, 160, 131, 129, 117, 45, 242, 3, 132>>) { %SummaryAggregate{ summary_time: ~U[2022-03-01 00:00:00Z], @@ -354,7 +364,9 @@ defmodule Archethic.BeaconChain.SummaryAggregate do 249, 138, 85, 71, 127, 190, 20, 186, 69, 131, 97, 194, 30, 71, 116>>, type: :transfer, timestamp: ~U[2022-02-01 10:00:00.204Z], - fee: 10_000_000 + fee: 10_000_000, + validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> }, confirmations: [ { diff --git a/lib/archethic/transaction_chain.ex b/lib/archethic/transaction_chain.ex index 41a1f65c3..15a20c235 100644 --- a/lib/archethic/transaction_chain.ex +++ b/lib/archethic/transaction_chain.ex @@ -643,10 +643,7 @@ defmodule Archethic.TransactionChain do case get_transaction(address, [ :address, :type, - validation_stamp: [ - :timestamp, - ledger_operations: [:fee, :transaction_movements] - ] + :validation_stamp ]) do {:ok, tx} -> {:ok, TransactionSummary.from_transaction(tx)} diff --git a/lib/archethic/transaction_chain/transaction_summary.ex b/lib/archethic/transaction_chain/transaction_summary.ex index 9178d5060..42b6b0fd7 100644 --- a/lib/archethic/transaction_chain/transaction_summary.ex +++ b/lib/archethic/transaction_chain/transaction_summary.ex @@ -2,7 +2,15 @@ defmodule Archethic.TransactionChain.TransactionSummary do @moduledoc """ Represents transaction header or extract to summarize it """ - defstruct [:timestamp, :address, :type, :fee, movements_addresses: []] + defstruct [ + :timestamp, + :address, + :type, + :fee, + :validation_stamp_checksum, + movements_addresses: [], + version: 1 + ] alias Archethic.TransactionChain.Transaction alias Archethic.TransactionChain.Transaction.ValidationStamp @@ -12,11 +20,13 @@ defmodule Archethic.TransactionChain.TransactionSummary do alias Archethic.Utils.VarInt @type t :: %__MODULE__{ + version: non_neg_integer(), timestamp: DateTime.t(), address: binary(), movements_addresses: list(binary()), type: Transaction.transaction_type(), - fee: pos_integer() + fee: pos_integer(), + validation_stamp_checksum: binary() } @doc """ @@ -26,20 +36,24 @@ defmodule Archethic.TransactionChain.TransactionSummary do def from_transaction(%Transaction{ address: address, type: type, - validation_stamp: %ValidationStamp{ - timestamp: timestamp, - ledger_operations: - operations = %LedgerOperations{ - fee: fee - } - } + validation_stamp: + validation_stamp = %ValidationStamp{ + timestamp: timestamp, + ledger_operations: + operations = %LedgerOperations{ + fee: fee + } + } }) do + validation_stamp_checksum = :crypto.hash(:sha256, ValidationStamp.serialize(validation_stamp)) + %__MODULE__{ address: address, timestamp: timestamp, movements_addresses: LedgerOperations.movement_addresses(operations), type: type, - fee: fee + fee: fee, + validation_stamp_checksum: validation_stamp_checksum } end @@ -57,10 +71,14 @@ defmodule Archethic.TransactionChain.TransactionSummary do ...> <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>> ...> ], - ...> fee: 10_000_000 + ...> fee: 10_000_000, + ...> validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> ...> } ...> |> TransactionSummary.serialize() << + # Version + 1, # Address 0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, 168, 212, 53, 82, 220, 22, 56, 222, 223, 127, 16, 172, 142, 218, 41, 247, @@ -74,22 +92,27 @@ defmodule Archethic.TransactionChain.TransactionSummary do 1, 1, # Movement address 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, - 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12 + 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, + # Validation stamp checksum + 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219 >> """ @spec serialize(t()) :: binary() def serialize(%__MODULE__{ + version: version, address: address, timestamp: timestamp, type: type, movements_addresses: movements_addresses, - fee: fee + fee: fee, + validation_stamp_checksum: validation_stamp_checksum }) do encoded_movement_addresses_len = length(movements_addresses) |> VarInt.from_value() - <> + :erlang.list_to_binary(movements_addresses)::binary, validation_stamp_checksum::binary>> end @doc """ @@ -97,14 +120,17 @@ defmodule Archethic.TransactionChain.TransactionSummary do ## Example - iex> <<0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, + iex> <<1, 0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, ...> 168, 212, 53, 82, 220, 22, 56, 222, 223, 127, 16, 172, 142, 218, 41, 247, 0, 0, 1, 114, 236, 9, 2, 168, ...> 253, 0, 0, 0, 0, 0, 152, 150, 128, ...> 1, 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, - ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>> + ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, + ...> 17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + ...> 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> ...> |> TransactionSummary.deserialize() { %TransactionSummary{ + version: 1, address: <<0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, 168, 212, 53, 82, 220, 22, 56, 222, 223, 127, 16, 172, 142, 218, 41, 247>>, timestamp: ~U[2020-06-25 15:11:53.000Z], @@ -113,26 +139,32 @@ defmodule Archethic.TransactionChain.TransactionSummary do <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>> ], - fee: 10_000_000 + fee: 10_000_000, + validation_stamp_checksum: <<17, 8, 18, 246, 127, 161, 225, 240, 17, 127, 111, 61, 112, 36, 28, 26, 66, + 167, 176, 119, 17, 169, 60, 36, 119, 204, 81, 109, 144, 66, 249, 219>> }, "" } """ @spec deserialize(bitstring()) :: {t(), bitstring()} - def deserialize(data) when is_bitstring(data) do + def deserialize(<>) do {address, <>} = - Utils.deserialize_address(data) + Utils.deserialize_address(rest) {nb_movements, rest} = rest |> VarInt.get_value() - {addresses, rest} = Utils.deserialize_addresses(rest, nb_movements, []) + + {addresses, <>} = + Utils.deserialize_addresses(rest, nb_movements, []) { %__MODULE__{ + version: version, address: address, timestamp: DateTime.from_unix!(timestamp, :millisecond), type: Transaction.parse_type(type), movements_addresses: addresses, - fee: fee + fee: fee, + validation_stamp_checksum: validation_stamp_checksum }, rest } @@ -144,14 +176,16 @@ defmodule Archethic.TransactionChain.TransactionSummary do timestamp: timestamp, type: type, movements_addresses: movements_addresses, - fee: fee + fee: fee, + validation_stamp_checksum: validation_stamp_checksum }) do %{ address: address, timestamp: timestamp, type: Atom.to_string(type), movements_addresses: movements_addresses, - fee: fee + fee: fee, + validation_stamp_checksum: validation_stamp_checksum } end @@ -161,14 +195,16 @@ defmodule Archethic.TransactionChain.TransactionSummary do timestamp: timestamp, type: type, movements_addresses: movements_addresses, - fee: fee + fee: fee, + validation_stamp_checksum: validation_stamp_checksum }) do %__MODULE__{ address: address, timestamp: timestamp, type: String.to_atom(type), movements_addresses: movements_addresses, - fee: fee + fee: fee, + validation_stamp_checksum: validation_stamp_checksum } end end diff --git a/lib/archethic_web/graphql_schema/beacon_chain_summary_type.ex b/lib/archethic_web/graphql_schema/beacon_chain_summary_type.ex index 37fb75088..d06333e8e 100644 --- a/lib/archethic_web/graphql_schema/beacon_chain_summary_type.ex +++ b/lib/archethic_web/graphql_schema/beacon_chain_summary_type.ex @@ -50,6 +50,7 @@ defmodule ArchethicWeb.GraphQLSchema.BeaconChainSummary do field(:movements_addresses, list_of(:address)) field(:type, :string) field(:fee, :integer) + field(:validation_stamp_checksum, :hash) end scalar :p2p_availabilities do diff --git a/test/archethic/beacon_chain/subset/summary_cache_test.exs b/test/archethic/beacon_chain/subset/summary_cache_test.exs index 3696c2b3d..8d9d63e3f 100644 --- a/test/archethic/beacon_chain/subset/summary_cache_test.exs +++ b/test/archethic/beacon_chain/subset/summary_cache_test.exs @@ -33,7 +33,8 @@ defmodule Archethic.BeaconChain.Subset.SummaryCacheTest do timestamp: ~U[2020-06-25 15:11:53.000Z], type: :transfer, movements_addresses: [], - fee: 10_000_000 + fee: 10_000_000, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) }, confirmations: [ {0, diff --git a/test/archethic/beacon_chain/subset_test.exs b/test/archethic/beacon_chain/subset_test.exs index 141057202..d5b52dbbd 100644 --- a/test/archethic/beacon_chain/subset_test.exs +++ b/test/archethic/beacon_chain/subset_test.exs @@ -90,7 +90,8 @@ defmodule Archethic.BeaconChain.SubsetTest do address: tx_address, timestamp: tx_time, type: :node, - fee: 0 + fee: 0, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } sig = Crypto.sign_with_last_node_key(TransactionSummary.serialize(tx_summary)) @@ -133,7 +134,8 @@ defmodule Archethic.BeaconChain.SubsetTest do address: tx_address, timestamp: tx_time, type: :node, - fee: 0 + fee: 0, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } tx_summary_payload = TransactionSummary.serialize(tx_summary) @@ -194,7 +196,8 @@ defmodule Archethic.BeaconChain.SubsetTest do address: tx_address, timestamp: tx_time, type: :node, - fee: 0 + fee: 0, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } sig = Crypto.sign_with_last_node_key(TransactionSummary.serialize(tx_summary)) @@ -213,7 +216,8 @@ defmodule Archethic.BeaconChain.SubsetTest do address: tx_address2, timestamp: tx_time, type: :node, - fee: 0 + fee: 0, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } sig2 = Crypto.sign_with_last_node_key(TransactionSummary.serialize(tx_summary)) @@ -268,7 +272,8 @@ defmodule Archethic.BeaconChain.SubsetTest do <<0, 0, 8, 253, 201, 142, 182, 78, 169, 132, 29, 19, 74, 3, 142, 207, 219, 127, 147, 40, 24, 44, 170, 214, 171, 224, 29, 177, 205, 226, 88, 62, 248, 84>> ], - fee: 0 + fee: 0, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } tx_summary_payload = TransactionSummary.serialize(tx_summary) @@ -364,7 +369,8 @@ defmodule Archethic.BeaconChain.SubsetTest do <<0, 0, 8, 253, 201, 142, 182, 78, 169, 132, 29, 19, 74, 3, 142, 207, 219, 127, 147, 40, 24, 44, 170, 214, 171, 224, 29, 177, 205, 226, 88, 62, 248, 84>> ], - fee: 0 + fee: 0, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } send( @@ -452,7 +458,8 @@ defmodule Archethic.BeaconChain.SubsetTest do <<0, 0, 8, 253, 201, 142, 182, 78, 169, 132, 29, 19, 74, 3, 142, 207, 219, 127, 147, 40, 24, 44, 170, 214, 171, 224, 29, 177, 205, 226, 88, 62, 248, 84>> ], - fee: 0 + fee: 0, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } tx_summary_payload = TransactionSummary.serialize(tx_summary) diff --git a/test/archethic/beacon_chain_test.exs b/test/archethic/beacon_chain_test.exs index 24fc767d5..ff04f3d8c 100644 --- a/test/archethic/beacon_chain_test.exs +++ b/test/archethic/beacon_chain_test.exs @@ -189,7 +189,8 @@ defmodule Archethic.BeaconChainTest do address: addr1, timestamp: DateTime.utc_now(), type: :transfer, - fee: 100_000_000 + fee: 100_000_000, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } nodes = P2P.authorized_and_available_nodes() |> Enum.sort_by(& &1.first_public_key) @@ -244,7 +245,8 @@ defmodule Archethic.BeaconChainTest do address: addr1, timestamp: DateTime.utc_now(), type: :transfer, - fee: 100_000_000 + fee: 100_000_000, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) } summary_v1 = %Summary{ @@ -285,7 +287,8 @@ defmodule Archethic.BeaconChainTest do address: addr2, timestamp: DateTime.utc_now(), type: :transfer, - fee: 100_000_000 + fee: 100_000_000, + validation_stamp_checksum: :crypto.strong_rand_bytes(32) }, confirmations: [node1, node2, node3, node4] diff --git a/test/archethic/db/embedded_impl_test.exs b/test/archethic/db/embedded_impl_test.exs index f21772209..3ca1a2171 100644 --- a/test/archethic/db/embedded_impl_test.exs +++ b/test/archethic/db/embedded_impl_test.exs @@ -247,7 +247,8 @@ defmodule Archethic.DB.EmbeddedTest do type: :transfer, address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, fee: 100_000_000, - timestamp: ~U[2020-08-31 20:00:00.232Z] + timestamp: ~U[2020-08-31 20:00:00.232Z], + validation_stamp_checksum: :crypto.strong_rand_bytes(32) }, confirmations: Enum.map(0..2, &{&1, "signature#{&1}"}) }