Skip to content

Commit

Permalink
Send all signer public keys (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
GhenadieVP committed Mar 31, 2023
1 parent 2f36d36 commit da4c6ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
27 changes: 21 additions & 6 deletions Sources/Clients/TransactionClient/TransactionClient+Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ extension TransactionClient {
manifest: TransactionManifest,
makeTransactionHeaderInput: MakeTransactionHeaderInput,
getNotaryAndSigners: @Sendable (AccountAddressesInvolvedInTransactionRequest) async throws -> NotaryAndSigners
) async -> Result<(intent: TransactionIntent, notaryAndSigners: NotaryAndSigners), TransactionFailure.FailedToPrepareForTXSigning> {
) async -> Result<(intent: TransactionIntent, notaryAndSigners: NotaryAndSigners, signerPublicKeys: [Engine.PublicKey]), TransactionFailure.FailedToPrepareForTXSigning> {
let nonce = engineToolkitClient.generateTXNonce()
let epoch: Epoch
do {
Expand Down Expand Up @@ -416,6 +416,19 @@ extension TransactionClient {
return .failure(.failedToLoadNotaryPublicKey)
}

var accountsToSignPublicKeys: [Engine.PublicKey] = []
do {
for account in notaryAndSigners.accountsNeededToSign {
switch account.securityState {
case let .unsecured(unsecuredControl):
let key = try unsecuredControl.genesisFactorInstance.publicKey.intoEngine()
accountsToSignPublicKeys.append(key)
}
}
} catch {
return .failure(.failedToLoadSignerPublicKeys)
}

let header = TransactionHeader(
version: version,
networkId: networkID,
Expand All @@ -433,7 +446,7 @@ extension TransactionClient {
manifest: manifest
)

return .success((intent, notaryAndSigners))
return .success((intent, notaryAndSigners, accountsToSignPublicKeys))
}

@Sendable
Expand Down Expand Up @@ -481,7 +494,8 @@ extension TransactionClient {
).map {
GatewayAPI.TransactionPreviewRequest(
rawManifest: request.manifestToSign,
header: $0.intent.header
header: $0.intent.header,
signerPublicKeys: $0.signerPublicKeys
)
}
}
Expand All @@ -499,7 +513,7 @@ extension TransactionClient {
getNotaryAndSigners: getNotaryAndSigners
).mapError {
TransactionFailure.failedToPrepareForTXSigning($0)
}.asyncFlatMap { intent, notaryAndSigners in
}.asyncFlatMap { intent, notaryAndSigners, _ in
await signAndSubmit(transactionIntent: intent, notaryAndSigners: notaryAndSigners)
}
}
Expand Down Expand Up @@ -702,7 +716,8 @@ extension IdentifiedArrayOf {
extension GatewayAPI.TransactionPreviewRequest {
init(
rawManifest: TransactionManifest,
header: TransactionHeader
header: TransactionHeader,
signerPublicKeys: [Engine.PublicKey]
) {
let manifestString = {
switch rawManifest.instructions {
Expand All @@ -728,7 +743,7 @@ extension GatewayAPI.TransactionPreviewRequest {
costUnitLimit: .init(header.costUnitLimit),
tipPercentage: .init(header.tipPercentage),
nonce: .init(header.nonce.rawValue),
signerPublicKeys: [GatewayAPI.PublicKey(from: header.publicKey)],
signerPublicKeys: signerPublicKeys.map { GatewayAPI.PublicKey(from: $0) },
flags: flags
)
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/Clients/TransactionClient/TransactionFailure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension TransactionFailure {
switch error {
case .failedToFindAccountWithEnoughFundsToLockFee:
return (errorKind: .failedToFindAccountWithEnoughFundsToLockFee, message: error.errorDescription)
case .failedToGetEpoch, .failedToLoadNotaryAndSigners, .failedToLoadNotaryPublicKey, .failedToParseTXItIsProbablyInvalid:
case .failedToGetEpoch, .failedToLoadNotaryAndSigners, .failedToLoadNotaryPublicKey, .failedToLoadSignerPublicKeys, .failedToParseTXItIsProbablyInvalid:
return (errorKind: .failedToPrepareTransaction, message: error.errorDescription)
}

Expand Down Expand Up @@ -106,6 +106,7 @@ extension TransactionFailure {
case failedToGetEpoch
case failedToLoadNotaryAndSigners
case failedToLoadNotaryPublicKey
case failedToLoadSignerPublicKeys
case failedToFindAccountWithEnoughFundsToLockFee

public var errorDescription: String? {
Expand All @@ -116,6 +117,8 @@ extension TransactionFailure {
return "Failed to get epoch"
case .failedToLoadNotaryPublicKey:
return "Failed to load notary public key"
case .failedToLoadSignerPublicKeys:
return "Failed to load signer public keys"
case .failedToLoadNotaryAndSigners:
return "Failed to load notary and signers"
case .failedToFindAccountWithEnoughFundsToLockFee:
Expand Down

0 comments on commit da4c6ec

Please sign in to comment.