Skip to content

Commit

Permalink
feat(HIP-844): add signer nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyLB authored Mar 12, 2024
1 parent 1f73ffc commit 6c57705
Show file tree
Hide file tree
Showing 20 changed files with 625 additions and 107 deletions.
13 changes: 11 additions & 2 deletions Sources/Hedera/Contract/ContractFunctionResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public struct ContractFunctionResult {
/// This is always empty in a ContractLocalCallQuery response, since no internal creations can happen in a static EVM call.
public let contractNonces: [ContractNonceInfo]

/// If not null this field specifies what the value of the signer account nonce is post transaction execution.
/// For transactions that don't update the signer nonce (like HAPI ContractCall and ContractCreate transactions) this field should be null.
public let signerNonce: UInt64?

internal init(
contractId: ContractId,
evmAddress: ContractId? = nil,
Expand All @@ -81,7 +85,8 @@ public struct ContractFunctionResult {
bytes: Data,
senderAccountId: AccountId? = nil,
logs: [ContractLogInfo] = [],
contractNonces: [ContractNonceInfo] = []
contractNonces: [ContractNonceInfo] = [],
signerNonce: UInt64? = nil
) {
self.contractId = contractId
self.evmAddress = evmAddress
Expand All @@ -95,6 +100,7 @@ public struct ContractFunctionResult {
self.senderAccountId = senderAccountId
self.logs = logs
self.contractNonces = contractNonces
self.signerNonce = signerNonce
}

private func getFixedBytesAt(slot: UInt, size: UInt) -> Data? {
Expand Down Expand Up @@ -244,6 +250,8 @@ extension ContractFunctionResult: TryFromProtobuf {

let contractId = try ContractId.fromProtobuf(proto.contractID)

let signerNonce = proto.hasSignerNonce ? UInt64(proto.signerNonce.value) : nil

self.init(
contractId: contractId,
evmAddress: proto.hasEvmAddress
Expand All @@ -257,7 +265,8 @@ extension ContractFunctionResult: TryFromProtobuf {
bytes: bytes,
senderAccountId: proto.hasSenderID ? try .fromProtobuf(proto.senderID) : nil,
logs: try .fromProtobuf(proto.logInfo),
contractNonces: try .fromProtobuf(proto.contractNonces)
contractNonces: try .fromProtobuf(proto.contractNonces),
signerNonce: signerNonce
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Hedera/Status.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ public enum Status: Equatable {

extension Status: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Status] = [
public static let allCases: [Status] = [
.ok,
.invalidTransaction,
.payerAccountNotFound,
Expand Down
16 changes: 8 additions & 8 deletions Sources/HederaProtobufs/Services/basic_types.pb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public enum Proto_TokenType: SwiftProtobuf.Enum {

extension Proto_TokenType: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Proto_TokenType] = [
public static let allCases: [Proto_TokenType] = [
.fungibleCommon,
.nonFungibleUnique,
]
Expand Down Expand Up @@ -149,7 +149,7 @@ public enum Proto_SubType: SwiftProtobuf.Enum {

extension Proto_SubType: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Proto_SubType] = [
public static let allCases: [Proto_SubType] = [
.default,
.tokenFungibleCommon,
.tokenNonFungibleUnique,
Expand Down Expand Up @@ -203,7 +203,7 @@ public enum Proto_TokenSupplyType: SwiftProtobuf.Enum {

extension Proto_TokenSupplyType: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Proto_TokenSupplyType] = [
public static let allCases: [Proto_TokenSupplyType] = [
.infinite,
.finite,
]
Expand Down Expand Up @@ -258,7 +258,7 @@ public enum Proto_TokenFreezeStatus: SwiftProtobuf.Enum {

extension Proto_TokenFreezeStatus: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Proto_TokenFreezeStatus] = [
public static let allCases: [Proto_TokenFreezeStatus] = [
.freezeNotApplicable,
.frozen,
.unfrozen,
Expand Down Expand Up @@ -313,7 +313,7 @@ public enum Proto_TokenKycStatus: SwiftProtobuf.Enum {

extension Proto_TokenKycStatus: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Proto_TokenKycStatus] = [
public static let allCases: [Proto_TokenKycStatus] = [
.kycNotApplicable,
.granted,
.revoked,
Expand Down Expand Up @@ -368,7 +368,7 @@ public enum Proto_TokenPauseStatus: SwiftProtobuf.Enum {

extension Proto_TokenPauseStatus: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Proto_TokenPauseStatus] = [
public static let allCases: [Proto_TokenPauseStatus] = [
.pauseNotApplicable,
.paused,
.unpaused,
Expand Down Expand Up @@ -842,7 +842,7 @@ public enum Proto_HederaFunctionality: SwiftProtobuf.Enum {

extension Proto_HederaFunctionality: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Proto_HederaFunctionality] = [
public static let allCases: [Proto_HederaFunctionality] = [
.none,
.cryptoTransfer,
.cryptoUpdate,
Expand Down Expand Up @@ -2192,7 +2192,7 @@ public struct Proto_TransactionFeeSchedule {
}

///*
/// The total fee charged for a transaction. It is composed of three components a node fee that
/// The total fee charged for a transaction. It is composed of three components - a node fee that
/// compensates the specific node that submitted the transaction, a network fee that compensates the
/// network for assigning the transaction a consensus timestamp, and a service fee that compensates
/// the network for the ongoing maintenance of the consequences of the transaction.
Expand Down
4 changes: 2 additions & 2 deletions Sources/HederaProtobufs/Services/contract_call.pb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAP

///*
/// Call a function of the given smart contract instance, giving it functionParameters as its inputs.
/// The call can use at maximum the given amount of gas the paying account will not be charged for
/// The call can use at maximum the given amount of gas - the paying account will not be charged for
/// any unspent gas.
///
/// If this function results in data being stored, an amount of gas is calculated that reflects this
/// storage burden.
///
/// The amount of gas used, as well as other attributes of the transaction, e.g. size, number of
/// signatures to be verified, determine the fee for the transaction which is charged to the paying
/// signatures to be verified, determine the fee for the transaction - which is charged to the paying
/// account.
public struct Proto_ContractCallTransactionBody {
// SwiftProtobuf.Message conformance is added in an extension below. See the
Expand Down
21 changes: 21 additions & 0 deletions Sources/HederaProtobufs/Services/contract_call_local.pb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ public struct Proto_ContractFunctionResult {
set {_uniqueStorage()._contractNonces = newValue}
}

///*
/// If not null this field specifies what the value of the signer account nonce is post transaction execution.
/// For transactions that don't update the signer nonce, this field should be null.
public var signerNonce: SwiftProtobuf.Google_Protobuf_Int64Value {
get {return _storage._signerNonce ?? SwiftProtobuf.Google_Protobuf_Int64Value()}
set {_uniqueStorage()._signerNonce = newValue}
}

/// Returns true if `signerNonce` has been explicitly set.
public var hasSignerNonce: Bool {return _storage._signerNonce != nil}
/// Clears the value of `signerNonce`. Subsequent reads from it will return its default value.
public mutating func clearSignerNonce() {_uniqueStorage()._signerNonce = nil}

public var unknownFields = SwiftProtobuf.UnknownStorage()

public init() {}
Expand Down Expand Up @@ -404,6 +417,7 @@ extension Proto_ContractFunctionResult: SwiftProtobuf.Message, SwiftProtobuf._Me
12: .same(proto: "functionParameters"),
13: .standard(proto: "sender_id"),
14: .standard(proto: "contract_nonces"),
15: .standard(proto: "signer_nonce"),
]

fileprivate class _StorageClass {
Expand All @@ -420,6 +434,7 @@ extension Proto_ContractFunctionResult: SwiftProtobuf.Message, SwiftProtobuf._Me
var _functionParameters: Data = Data()
var _senderID: Proto_AccountID? = nil
var _contractNonces: [Proto_ContractNonceInfo] = []
var _signerNonce: SwiftProtobuf.Google_Protobuf_Int64Value? = nil

static let defaultInstance = _StorageClass()

Expand All @@ -439,6 +454,7 @@ extension Proto_ContractFunctionResult: SwiftProtobuf.Message, SwiftProtobuf._Me
_functionParameters = source._functionParameters
_senderID = source._senderID
_contractNonces = source._contractNonces
_signerNonce = source._signerNonce
}
}

Expand Down Expand Up @@ -470,6 +486,7 @@ extension Proto_ContractFunctionResult: SwiftProtobuf.Message, SwiftProtobuf._Me
case 12: try { try decoder.decodeSingularBytesField(value: &_storage._functionParameters) }()
case 13: try { try decoder.decodeSingularMessageField(value: &_storage._senderID) }()
case 14: try { try decoder.decodeRepeatedMessageField(value: &_storage._contractNonces) }()
case 15: try { try decoder.decodeSingularMessageField(value: &_storage._signerNonce) }()
default: break
}
}
Expand Down Expand Up @@ -521,6 +538,9 @@ extension Proto_ContractFunctionResult: SwiftProtobuf.Message, SwiftProtobuf._Me
if !_storage._contractNonces.isEmpty {
try visitor.visitRepeatedMessageField(value: _storage._contractNonces, fieldNumber: 14)
}
try { if let v = _storage._signerNonce {
try visitor.visitSingularMessageField(value: v, fieldNumber: 15)
} }()
}
try unknownFields.traverse(visitor: &visitor)
}
Expand All @@ -543,6 +563,7 @@ extension Proto_ContractFunctionResult: SwiftProtobuf.Message, SwiftProtobuf._Me
if _storage._functionParameters != rhs_storage._functionParameters {return false}
if _storage._senderID != rhs_storage._senderID {return false}
if _storage._contractNonces != rhs_storage._contractNonces {return false}
if _storage._signerNonce != rhs_storage._signerNonce {return false}
return true
}
if !storagesAreEqual {return false}
Expand Down
2 changes: 1 addition & 1 deletion Sources/HederaProtobufs/Services/freeze_type.pb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public enum Proto_FreezeType: SwiftProtobuf.Enum {

extension Proto_FreezeType: CaseIterable {
// The compiler won't synthesize support with the UNRECOGNIZED case.
public static var allCases: [Proto_FreezeType] = [
public static let allCases: [Proto_FreezeType] = [
.unknownFreezeType,
.freezeOnly,
.prepareUpgrade,
Expand Down
Loading

0 comments on commit 6c57705

Please sign in to comment.