Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 6c6b2ac

Browse files
authored
Merge pull request #52 from OpenZesame/increase_default_gasLimit
Increase min gasLimit to 50 for payments
2 parents aa0b8a7 + 597d839 commit 6c6b2ac

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Sources/Zesame/Models/Manual/Payment/GasLimit.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import Foundation
2626

2727
public typealias GasLimit = Int
2828
public extension GasLimit {
29-
static var defaultGasLimit: GasLimit {
30-
return 1
29+
static var defaultGasLimit: Self = Self.minimum
30+
31+
static var minimum: Self {
32+
return 50
3133
}
3234
}

Sources/Zesame/Models/Manual/Payment/Payment.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,34 @@ public struct Payment {
3737
gasLimit: GasLimit = .defaultGasLimit,
3838
gasPrice: GasPrice,
3939
nonce: Nonce = 0
40-
) {
40+
) throws {
41+
guard gasLimit >= GasLimit.minimum else { throw Error.gasLimitTooLow(got: gasLimit, butMinIs: GasLimit.minimum) }
4142
self.recipient = recipient
4243
self.amount = amount
4344
self.gasLimit = gasLimit
4445
self.gasPrice = gasPrice
4546
self.nonce = nonce.increasedByOne()
4647
}
48+
49+
enum Error: Swift.Error {
50+
case gasLimitTooLow(got: GasLimit, butMinIs: GasLimit)
51+
}
52+
4753
}
4854

4955
public extension Payment {
56+
57+
58+
static func withMinimumGasLimit(
59+
to recipient: LegacyAddress,
60+
amount: ZilAmount,
61+
gasPrice: GasPrice,
62+
nonce: Nonce = 0
63+
) -> Self {
64+
try! .init(to: recipient, amount: amount, gasLimit: GasLimit.minimum, gasPrice: gasPrice, nonce: nonce)
65+
}
66+
67+
5068
static func estimatedTotalTransactionFee(gasPrice: GasPrice, gasLimit: GasLimit = .defaultGasLimit) throws -> Qa {
5169
return Qa(qa: Qa.Magnitude(gasLimit) * gasPrice.qa)
5270
}

Tests/ZesameTests/TransactionSigningTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ class TransactionSigningTests: XCTestCase {
3939
let publicKey = PublicKey(privateKey: privateKey)
4040

4141
let unsignedTx = Transaction(
42-
payment: Payment(
42+
payment: Payment.withMinimumGasLimit(
4343
to: try! LegacyAddress(string: "9Ca91EB535Fb92Fda5094110FDaEB752eDb9B039"),
4444
amount: 15,
45-
gasLimit: 1,
4645
gasPrice: GasPrice.min,
4746
nonce: Nonce(3)
4847
),
@@ -73,10 +72,10 @@ private let expectedTransactionJSONString = """
7372
"pubKey" : "034AE47910D58B9BDE819C3CFFA8DE4441955508DB00AA2540DB8E6BF6E99ABC1B",
7473
"data" : null,
7574
"code" : null,
76-
"signature" : "1727048B9F200D07E6E2D8EFF6BA3E54BF491589CCB55D872E242505B72E6CA74E022AC954DF21420AF8737C89A7E9048B75B531F6865B78B1E2A864169ED64D",
77-
"gasLimit" : "1",
75+
"signature" : "379AA79C8A38A51B3D20232F89D8CF06B7CB2C52D5B42F96280BCD5EE3B1E848E9778C3E0AFE7164F3A913B6E31B88AC226D3816638B03D9718BBDC6F21909DD",
76+
"gasLimit" : "50",
7877
"version" : 65537,
79-
"gasPrice" : "1000000000",
78+
"gasPrice" : "100000000000",
8079
"nonce" : 4
8180
}
8281
"""

0 commit comments

Comments
 (0)