-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #523 from mloit/feature/transaction-metadata
- Loading branch information
Showing
5 changed files
with
70 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Package: web3swift | ||
// Created by Alex Vlasov. | ||
// Copyright © 2018 Alex Vlasov. All rights reserved. | ||
// | ||
// Additions for metadata by Mark Loit 2022 | ||
|
||
import Foundation | ||
import BigInt | ||
|
||
/// This structure holds additional data | ||
/// returned by nodes when reading a transaction | ||
/// from the blockchain. The data here is not | ||
/// part of the transaction itself | ||
public struct EthereumMetadata { | ||
|
||
/// hash for the block that contains this transaction on chain | ||
var blockHash: Data? | ||
|
||
/// block number for the block containing this transaction on chain | ||
var blockNumber: BigUInt? | ||
|
||
/// index for this transaction within the containing block | ||
var transactionIndex: UInt? | ||
|
||
/// hash for this transaction as returned by the node [not computed] | ||
/// this can be used for validation against the computed hash returned | ||
/// by the transaction envelope. | ||
var transactionHash: Data? | ||
|
||
/// gasPrice value returned by the node | ||
/// note this is a duplicate value for legacy and EIP-2930 transaction types | ||
/// but is included here since EIP-1559 does not contain a `gasPrice`, but | ||
/// nodes still report the value. | ||
var gasPrice: BigUInt? | ||
} | ||
|
||
public extension EthereumMetadata { | ||
private enum CodingKeys: String, CodingKey { | ||
case blockHash | ||
case blockNumber | ||
case transactionIndex | ||
case transactionHash | ||
case gasPrice | ||
} | ||
|
||
/// since metadata realistically can only come when a transaction is created from | ||
/// JSON returned by a node, we only provide an intializer from JSON | ||
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
self.blockHash = try container.decodeHexIfPresent(Data.self, forKey: .blockHash) | ||
self.transactionHash = try container.decodeHexIfPresent(Data.self, forKey: .transactionHash) | ||
self.transactionIndex = try container.decodeHexIfPresent(UInt.self, forKey: .transactionIndex) | ||
self.blockNumber = try container.decodeHexIfPresent(BigUInt.self, forKey: .blockNumber) | ||
self.gasPrice = try container.decodeHexIfPresent(BigUInt.self, forKey: .gasPrice) | ||
} | ||
} |
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