-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/transaction metadata #523
Changes from all commits
b182a42
cbdde45
2bf9639
ba9aeea
fbb0726
4602cdf
f2f613a
45b60f6
878c2a9
e164bf6
d8a1daa
f28b306
11b8260
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,12 +41,6 @@ public struct EIP1559Envelope: EIP2718Envelope { | |
public var maxFeePerGas: BigUInt | ||
public var accessList: [AccessListEntry] // from EIP-2930 | ||
|
||
/// EIP-1159 trnsactions do not have a gasPrice parameter | ||
/// However, it appears that some nodes report a gasPrice, even for EIP-1159 transactions | ||
/// thus for a temporary workaround we capture and store gasPrice if initialized from a JSON transaction | ||
/// decided form a node. This is currently needed for Oracle to work | ||
private var gasPrice: BigUInt = 0 | ||
|
||
// for CustomStringConvertible | ||
public var description: String { | ||
var toReturn = "" | ||
|
@@ -76,9 +70,6 @@ public struct EIP1559Envelope: EIP2718Envelope { | |
value: value, | ||
data: data, | ||
gasLimit: gasLimit, | ||
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now | ||
gasPrice: gasPrice, | ||
|
||
maxFeePerGas: maxFeePerGas, | ||
maxPriorityFeePerGas: maxPriorityFeePerGas, | ||
accessList: accessList | ||
|
@@ -94,8 +85,6 @@ public struct EIP1559Envelope: EIP2718Envelope { | |
maxFeePerGas = val.maxFeePerGas ?? maxFeePerGas | ||
maxPriorityFeePerGas = val.maxPriorityFeePerGas ?? maxPriorityFeePerGas | ||
accessList = val.accessList ?? accessList | ||
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now | ||
gasPrice = val.gasPrice ?? gasPrice | ||
} | ||
} | ||
|
||
|
@@ -117,8 +106,6 @@ extension EIP1559Envelope { | |
case v | ||
case r | ||
case s | ||
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now | ||
case gasPrice | ||
} | ||
|
||
public init?(from decoder: Decoder) throws { | ||
|
@@ -147,9 +134,6 @@ extension EIP1559Envelope { | |
self.to = ethAddr | ||
} | ||
|
||
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's 1559 mistyped to 1159 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy paste when I did the workaround... this PR is removing it |
||
self.gasPrice = try container.decodeHexIfPresent(BigUInt.self, forKey: .gasPrice) ?? 5000000000 | ||
|
||
self.value = try container.decodeHexIfPresent(BigUInt.self, forKey: .value) ?? 0 | ||
self.maxPriorityFeePerGas = try container.decodeHexIfPresent(BigUInt.self, forKey: .maxPriorityFeePerGas) ?? 0 | ||
self.maxFeePerGas = try container.decodeHexIfPresent(BigUInt.self, forKey: .maxFeePerGas) ?? 0 | ||
|
@@ -212,7 +196,7 @@ extension EIP1559Envelope { | |
|
||
// swiftlint:disable force_unwrapping | ||
switch rlpItem[RlpKey.destination.rawValue]!.content { | ||
// swiftlint:enable force_unwrapping | ||
// swiftlint:enable force_unwrapping | ||
case .noItem: | ||
self.to = EthereumAddress.contractDeploymentAddress() | ||
case .data(let addressData): | ||
|
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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ public struct EthereumTransaction: CustomStringConvertible { | |
/// and type specific implementation | ||
internal var envelope: AbstractEnvelope | ||
|
||
/// storage container for additional metadata returned by the node | ||
/// when a transaction is decoded form a JSON stream | ||
public var meta: EthereumMetadata? | ||
|
||
// convenience accessors to the common envelope fields | ||
// everything else should come from getOpts/setOpts | ||
/// The type of the transacton being represented, see TransactionType enum | ||
|
@@ -227,6 +231,8 @@ extension EthereumTransaction: Decodable { | |
public init(from decoder: Decoder) throws { | ||
guard let env = try EnvelopeFactory.createEnvelope(from: decoder) else { throw Web3Error.dataError } | ||
self.envelope = env | ||
// capture any metadata that might be present | ||
self.meta = try EthereumMetadata(from: decoder) | ||
} | ||
} | ||
|
||
|
@@ -330,10 +336,7 @@ extension EthereumTransaction { | |
guard let env = self.envelope as? EIP2930Envelope else { preconditionFailure("Unable to downcast to EIP2930Envelope") } | ||
return env.parameters.gasPrice ?? 0 | ||
case .eip1559: | ||
// MARK: workaround for gasPrice coming from nodes for EIP-1159 - this allows Oracle to work for now | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's 1559 mistyped to 1159 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see previous comments |
||
guard let env = self.envelope as? EIP1559Envelope else { preconditionFailure("Unable to downcast to EIP1559Envelope") } | ||
return env.parameters.gasPrice ?? 0 | ||
// preconditionFailure("EIP1559Envelope has no member gasPrice") | ||
preconditionFailure("EIP1559Envelope has no member gasPrice") | ||
} | ||
} | ||
set(value) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Pod::Spec.new do |spec| | ||
spec.name = 'web3swift' | ||
spec.version = '2.5.1' | ||
spec.version = '2.6.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea why on earth GitHub is flagging this as a change being made here, as |
||
spec.ios.deployment_target = "9.0" | ||
spec.osx.deployment_target = "10.12" | ||
spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's 1559 mistyped to 1159
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, but it's a line being deleted, so no need to fix.