Skip to content

Commit

Permalink
add transaction message
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelPawelec-RDX committed Aug 15, 2023
1 parent 5ef4df9 commit 681842c
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ public TransactionStreamReader(INetworkConfigurationProvider networkConfiguratio
RawLedgerTransaction = true,
RawNotarizedTransaction = true,
RawSystemTransaction = true,
Message = true,
},
substateFormatOptions: new CoreModel.SubstateFormatOptions
{
Hash = false,
Raw = false,
Typed = true,
Previous = false,
},
sborFormatOptions: new CoreModel.SborFormatOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,9 @@ components:
$ref: "#/components/schemas/HexString"
receipt:
$ref: "#/components/schemas/TransactionReceipt"
message_hex:
$ref: "#/components/schemas/HexString"
message:
type: object
description: defined in core api specs.

TransactionStatus:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ protected CommittedTransactionInfo() { }
/// <param name="errorMessage">errorMessage.</param>
/// <param name="rawHex">Hex-encoded binary blob..</param>
/// <param name="receipt">receipt.</param>
/// <param name="messageHex">Hex-encoded binary blob..</param>
public CommittedTransactionInfo(long stateVersion = default(long), long epoch = default(long), long round = default(long), string roundTimestamp = default(string), TransactionStatus transactionStatus = default(TransactionStatus), string payloadHashHex = default(string), string intentHashHex = default(string), string feePaid = default(string), List<string> affectedGlobalEntities = default(List<string>), DateTime? confirmedAt = default(DateTime?), string errorMessage = default(string), string rawHex = default(string), TransactionReceipt receipt = default(TransactionReceipt), string messageHex = default(string))
/// <param name="message">defined in core api specs..</param>
public CommittedTransactionInfo(long stateVersion = default(long), long epoch = default(long), long round = default(long), string roundTimestamp = default(string), TransactionStatus transactionStatus = default(TransactionStatus), string payloadHashHex = default(string), string intentHashHex = default(string), string feePaid = default(string), List<string> affectedGlobalEntities = default(List<string>), DateTime? confirmedAt = default(DateTime?), string errorMessage = default(string), string rawHex = default(string), TransactionReceipt receipt = default(TransactionReceipt), Object message = default(Object))
{
this.StateVersion = stateVersion;
this.Epoch = epoch;
Expand All @@ -143,7 +143,7 @@ protected CommittedTransactionInfo() { }
this.ErrorMessage = errorMessage;
this.RawHex = rawHex;
this.Receipt = receipt;
this.MessageHex = messageHex;
this.Message = message;
}

/// <summary>
Expand Down Expand Up @@ -223,11 +223,11 @@ protected CommittedTransactionInfo() { }
public TransactionReceipt Receipt { get; set; }

/// <summary>
/// Hex-encoded binary blob.
/// defined in core api specs.
/// </summary>
/// <value>Hex-encoded binary blob.</value>
[DataMember(Name = "message_hex", EmitDefaultValue = true)]
public string MessageHex { get; set; }
/// <value>defined in core api specs.</value>
[DataMember(Name = "message", EmitDefaultValue = true)]
public Object Message { get; set; }

/// <summary>
/// Returns the string presentation of the object
Expand All @@ -250,7 +250,7 @@ public override string ToString()
sb.Append(" ErrorMessage: ").Append(ErrorMessage).Append("\n");
sb.Append(" RawHex: ").Append(RawHex).Append("\n");
sb.Append(" Receipt: ").Append(Receipt).Append("\n");
sb.Append(" MessageHex: ").Append(MessageHex).Append("\n");
sb.Append(" Message: ").Append(Message).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand Down Expand Up @@ -349,9 +349,9 @@ public bool Equals(CommittedTransactionInfo input)
this.Receipt.Equals(input.Receipt))
) &&
(
this.MessageHex == input.MessageHex ||
(this.MessageHex != null &&
this.MessageHex.Equals(input.MessageHex))
this.Message == input.Message ||
(this.Message != null &&
this.Message.Equals(input.Message))
);
}

Expand Down Expand Up @@ -404,9 +404,9 @@ public override int GetHashCode()
{
hashCode = (hashCode * 59) + this.Receipt.GetHashCode();
}
if (this.MessageHex != null)
if (this.Message != null)
{
hashCode = (hashCode * 59) + this.MessageHex.GetHashCode();
hashCode = (hashCode * 59) + this.Message.GetHashCode();
}
return hashCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ public static GatewayModel.CommittedTransactionInfo ToGatewayModel(
string? payloadHashHex = null;
string? intentHashHex = null;
string? rawHex = null;
string? messageHex = null;
JRaw? message = null;

if (lt is UserLedgerTransaction ult)
{
payloadHashHex = ult.PayloadHash.ToHex();
intentHashHex = ult.IntentHash.ToHex();
rawHex = optIns.RawHex ? ult.RawPayload.ToHex() : null;
messageHex = ult.Message?.ToHex();
message = new JRaw(ult.Message);
}

var receipt = new GatewayModel.TransactionReceipt
Expand Down Expand Up @@ -160,7 +160,7 @@ public static GatewayModel.CommittedTransactionInfo ToGatewayModel(
errorMessage: lt.EngineReceipt.ErrorMessage,
rawHex: rawHex,
receipt: receipt,
messageHex: messageHex
message: message
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ private async Task<ExtendLedgerReport> ProcessTransactions(ReadWriteDbContext db
PayloadHash = ult.NotarizedTransaction.GetHashBytes(),
IntentHash = ult.NotarizedTransaction.SignedIntent.Intent.GetHashBytes(),
SignedIntentHash = ult.NotarizedTransaction.SignedIntent.GetHashBytes(),
Message = ult.NotarizedTransaction.SignedIntent.Intent.Message?.ToJson(),
},
CoreModel.RoundUpdateLedgerTransaction => new RoundUpdateLedgerTransaction(),
_ => throw new UnreachableException(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,14 @@ public async Task<int> CopyLedgerTransaction(ICollection<LedgerTransaction> enti
return 0;
}

await using var writer = await _connection.BeginBinaryImportAsync("COPY ledger_transactions (state_version, message, epoch, round_in_epoch, index_in_epoch, index_in_round, is_end_of_epoch, fee_paid, tip_paid, affected_global_entities, round_timestamp, created_timestamp, normalized_round_timestamp, raw_payload, receipt_state_updates, receipt_status, receipt_fee_summary, receipt_error_message, receipt_output, receipt_next_epoch, receipt_event_sbors, receipt_event_schema_hashes, receipt_event_type_indexes, receipt_event_sbor_type_kinds, discriminator, payload_hash, intent_hash, signed_intent_hash) FROM STDIN (FORMAT BINARY)", token);
await using var writer = await _connection.BeginBinaryImportAsync("COPY ledger_transactions (state_version, epoch, round_in_epoch, index_in_epoch, index_in_round, is_end_of_epoch, fee_paid, tip_paid, affected_global_entities, round_timestamp, created_timestamp, normalized_round_timestamp, raw_payload, receipt_state_updates, receipt_status, receipt_fee_summary, receipt_error_message, receipt_output, receipt_next_epoch, receipt_event_sbors, receipt_event_schema_hashes, receipt_event_type_indexes, receipt_event_sbor_type_kinds, discriminator, payload_hash, intent_hash, signed_intent_hash, message) FROM STDIN (FORMAT BINARY)", token);

foreach (var lt in entities)
{
var discriminator = GetDiscriminator<LedgerTransactionType>(lt.GetType());

await writer.StartRowAsync(token);
await writer.WriteAsync(lt.StateVersion, NpgsqlDbType.Bigint, token);
await writer.WriteNullableAsync(lt.Message, NpgsqlDbType.Bytea, token);
await writer.WriteAsync(lt.Epoch, NpgsqlDbType.Bigint, token);
await writer.WriteAsync(lt.RoundInEpoch, NpgsqlDbType.Bigint, token);
await writer.WriteAsync(lt.IndexInEpoch, NpgsqlDbType.Bigint, token);
Expand Down Expand Up @@ -219,16 +218,19 @@ public async Task<int> CopyLedgerTransaction(ICollection<LedgerTransaction> enti
await writer.WriteNullAsync(token);
await writer.WriteNullAsync(token);
await writer.WriteNullAsync(token);
await writer.WriteNullAsync(token);
break;
case UserLedgerTransaction ult:
await writer.WriteAsync(ult.PayloadHash, NpgsqlDbType.Bytea, token);
await writer.WriteAsync(ult.IntentHash, NpgsqlDbType.Bytea, token);
await writer.WriteAsync(ult.SignedIntentHash, NpgsqlDbType.Bytea, token);
await writer.WriteAsync(ult.Message, NpgsqlDbType.Jsonb, token);
break;
case RoundUpdateLedgerTransaction:
await writer.WriteNullAsync(token);
await writer.WriteNullAsync(token);
await writer.WriteNullAsync(token);
await writer.WriteNullAsync(token);
break;
default:
throw new ArgumentOutOfRangeException(nameof(lt), lt, null);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
state_version = table.Column<long>(type: "bigint", nullable: false),
message = table.Column<byte[]>(type: "bytea", nullable: true),
epoch = table.Column<long>(type: "bigint", nullable: false),
round_in_epoch = table.Column<long>(type: "bigint", nullable: false),
index_in_epoch = table.Column<long>(type: "bigint", nullable: false),
Expand All @@ -424,7 +423,8 @@ protected override void Up(MigrationBuilder migrationBuilder)
discriminator = table.Column<LedgerTransactionType>(type: "ledger_transaction_type", nullable: false),
payload_hash = table.Column<byte[]>(type: "bytea", nullable: true),
intent_hash = table.Column<byte[]>(type: "bytea", nullable: true),
signed_intent_hash = table.Column<byte[]>(type: "bytea", nullable: true)
signed_intent_hash = table.Column<byte[]>(type: "bytea", nullable: true),
message = table.Column<string>(type: "jsonb", nullable: true)
},
constraints: table =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("boolean")
.HasColumnName("is_end_of_epoch");
b.Property<byte[]>("Message")
.HasColumnType("bytea")
.HasColumnName("message");
b.Property<DateTime>("NormalizedRoundTimestamp")
.HasColumnType("timestamp with time zone")
.HasColumnName("normalized_round_timestamp");
Expand Down Expand Up @@ -1841,6 +1837,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("bytea")
.HasColumnName("intent_hash");
b.Property<string>("Message")
.HasColumnType("jsonb")
.HasColumnName("message");
b.Property<byte[]>("PayloadHash")
.IsRequired()
.HasColumnType("bytea")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ internal abstract class LedgerTransaction
[Column("state_version")]
public long StateVersion { get; set; }

[Column("message")]
public byte[]? Message { get; set; }

[Column("epoch")]
public long Epoch { get; set; }

Expand Down Expand Up @@ -200,6 +197,9 @@ internal class UserLedgerTransaction : LedgerTransaction
/// </summary>
[Column("signed_intent_hash")]
public byte[] SignedIntentHash { get; set; }

[Column("message", TypeName = "jsonb")]
public string? Message { get; set; }
}

internal class RoundUpdateLedgerTransaction : LedgerTransaction
Expand Down

0 comments on commit 681842c

Please sign in to comment.