-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,51 @@ | ||
import Sodium | ||
|
||
public typealias Node = (accountId: AccountId, address: String) | ||
|
||
let defaultMaxTransactionFee = 100_000 | ||
let defaultMaxTransactionFee: UInt64 = 100_000_000 | ||
|
||
public struct Client { | ||
let operatorId: AccountId | ||
let operatorKey: Ed25519PrivateKey | ||
let operatorSigner: (Bytes) -> Bytes | ||
|
||
let nodes: [AccountId: Node] | ||
var node: AccountId? | ||
|
||
/// The default maximum fee for a transaction. | ||
/// This can be overridden for an individual transaction with `.setTransactionFee()`. | ||
let maxTransactionFee = defaultMaxTransactionFee | ||
|
||
// TODO: once queries are implemented | ||
// /// The maximum payment that can be automatically attached to a query. | ||
// /// If this is not set, payments will not be made automatically for queries. | ||
// /// This can be overridden for an individual query with `.setPaymentDefault()`. | ||
// var maxQueryPayment: UInt64? | ||
|
||
} | ||
|
||
public struct ClientBuilder { | ||
var operatorId: AccountId? | ||
var operatorKey: Ed25519PrivateKey? | ||
var node: Node? | ||
var operatorSigner: ((Bytes) -> Bytes)? | ||
var node: AccountId? | ||
|
||
public init() {} | ||
|
||
public mutating func setOperator(id: AccountId, secret: Ed25519PrivateKey) -> Self { | ||
operatorId = id | ||
operatorSigner = secret.sign | ||
|
||
return self | ||
} | ||
|
||
public mutating func setOperator(id: AccountId, signer: @escaping (Bytes) -> Bytes) -> Self { | ||
operatorId = id | ||
operatorSigner = signer | ||
|
||
return self | ||
} | ||
|
||
public mutating func setNode(_ id: AccountId) -> Self { | ||
node = id | ||
return self | ||
} | ||
} |
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,61 @@ | ||
import SwiftProtobuf | ||
import Foundation | ||
|
||
class AccountCreateTransaction: TransactionBuilder { | ||
public override init(client: Client) { | ||
super.init(client: client) | ||
|
||
var inner = Proto_CryptoCreateTransactionBody() | ||
// Required fixed autorenew duration (roughly 1/4 year) | ||
inner.autoRenewPeriod = TimeInterval(7_890_000).toProto() | ||
// Default to maximum values for record thresholds. Without this, records | ||
// would be auto-created whenever a send or receive transaction takes place | ||
// for this new account. This should be an explicit ask. | ||
inner.sendRecordThreshold = UInt64.max | ||
inner.receiveRecordThreshold = UInt64.max | ||
|
||
body.cryptoCreateAccount = inner | ||
} | ||
|
||
public func setKey(_ key: Ed25519PublicKey) -> Self { | ||
body.cryptoCreateAccount.key = key.toProto() | ||
|
||
return self | ||
} | ||
|
||
public func setInitialBalance(_ balance: UInt64) -> Self { | ||
body.cryptoCreateAccount.initialBalance = balance | ||
|
||
return self | ||
} | ||
|
||
public func setProxyAccountId(_ id: AccountId) -> Self { | ||
body.cryptoCreateAccount.proxyAccountID = id.toProto() | ||
|
||
return self | ||
} | ||
|
||
public func setSendRecordThreshold(_ threshold: UInt64) -> Self { | ||
body.cryptoCreateAccount.sendRecordThreshold = threshold | ||
|
||
return self | ||
} | ||
|
||
public func setReceiveRecordThreshold(_ threshold: UInt64) -> Self { | ||
body.cryptoCreateAccount.receiveRecordThreshold = threshold | ||
|
||
return self | ||
} | ||
|
||
public func setReceiverSignatureRequired(_ required: Bool) -> Self { | ||
body.cryptoCreateAccount.receiverSigRequired = required | ||
|
||
return self | ||
} | ||
|
||
public func setAutoRenewPeriod(_ period: TimeInterval) -> Self { | ||
body.cryptoCreateAccount.autoRenewPeriod = period.toProto() | ||
|
||
return self | ||
} | ||
} |
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