Skip to content

Commit

Permalink
Fix: multi-chunked transactions contain the same payer account id (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyLB authored Feb 15, 2024
1 parent beac23d commit 1f73ffc
Show file tree
Hide file tree
Showing 45 changed files with 180 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Account that will pay query and transaction fees
OPERATOR_ACCOUNT_ID=
OPERATOR_ID=

# Default private key to use to sign for all transactions and queries
OPERATOR_KEY=
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/swift-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,5 @@ jobs:
restore-keys: |
${{ runner.os }}-${{ matrix.swift }}-spm-
- name: "Create env file"
run: |
touch .env
echo TEST_OPERATOR_KEY="302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137" >> .env
echo TEST_OPERATOR_ID="0.0.2" >> .env
echo TEST_HEDERA_NETWORK="localhost" >> .env
echo TEST_RUN_NONFREE="1" >> .env
cat .env
- name: Start the local node
run: npx @hashgraph/hedera-local@2.13.0 start -d --network local

- name: Test
run: swift test

- name: Stop the local node
run: npx @hashgraph/hedera-local@2.13.0 stop
2 changes: 1 addition & 1 deletion Examples/AccountAlias/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/AccountAllowance/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/ConsensusPubSub/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/ConsensusPubSubChunked/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/ConsensusPubSubWithSubmitKey/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateAccount/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateAccountThresholdKey/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateFile/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateSimpleContract/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateStatefulContract/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateTopic/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/DeleteAccount/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/DeleteFile/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/FileAppendChunked/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/GetAccountInfo/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/GetExchangeRates/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/GetFileContents/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/MultiAppTransfer/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/MultiSigOffline/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/Prng/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/Schedule/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/ScheduleIdenticalTransaction/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/ScheduleMultiSigTransaction/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/ScheduledTransactionMultiSigThreshold/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/ScheduledTransfer/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/Staking/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/StakingWithUpdate/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/TopicWithAdminKey/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/TransferCrypto/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/TransferTokens/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
2 changes: 1 addition & 1 deletion Examples/UpdateAccountPublicKey/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal enum Program {
extension Environment {
/// Account ID for the operator to use in this example.
internal var operatorAccountId: AccountId {
AccountId(self["OPERATOR_ACCOUNT_ID"]!.stringValue)!
AccountId(self["OPERATOR_ID"]!.stringValue)!
}

/// Private key for the operator to use in this example.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protoc --grpc-swift_opt=Visibility=Public,FileNaming=PathToUnderscores,Server=fa
Before running the integration tests, an operator key, operator account id, and a network name must be set in an `.env` file.
```bash
# Account that will pay query and transaction fees
TEST_OPERATOR_ACCOUNT_ID=
TEST_OPERATOR_ID=
# Default private key to use to sign for all transactions and queries
TEST_OPERATOR_KEY=
# Network names: `"localhost"`, `"testnet"`, `"previewnet"`, `"mainnet"`
Expand All @@ -115,7 +115,7 @@ https://github.com/hashgraph/hedera-local-node

Once the local node is running in Docker, the appropriate `.env` values must be set:
```bash
TEST_OPERATOR_ACCOUNT_ID=0.0.2
TEST_OPERATOR_ID=0.0.2
TEST_OPERATOR_KEY=3030020100300706052b8104000a042204205bc004059ffa2943965d306f2c44d266255318b3775bacfec42a77ca83e998f2
TEST_NETWORK_NAME=localhost
```
Expand Down
11 changes: 11 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Release process for SWIFT SDK

## Release
1. Create a new git branch: `release/vX.Y.Z`.
>- Follows [semver 2.0](https://semver.org/spec/v2.0.0.html)
2. Run all tests against [hedera-local-node](https://github.com/hashgraph/hedera-local-node). Stop local-node once the tests are completed.
>- `swift test`
3. Create a new tag.
>- `git push -a <version> -m <version>`
4. Once branch has been approved and merged to main, document added features pertaining to the newest release.
>- [Tags and Releases for Swift SDK](https://github.com/hashgraph/hedera-sdk-swift/releases)
20 changes: 16 additions & 4 deletions Sources/Hedera/ChunkedTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ extension ChunkedTransaction.FirstChunkView: Execute {
internal var nodeAccountIds: [AccountId]? { transaction.nodeAccountIds }
internal var explicitTransactionId: TransactionId? { transaction.transactionId }
internal var requiresTransactionId: Bool { true }
internal var firstTransactionId: TransactionId? { nil }
internal var index: Int? { nil }

internal var operatorAccountId: AccountId? {
self.transaction.operatorAccountId
Expand Down Expand Up @@ -247,6 +249,14 @@ extension ChunkedTransaction.ChunkView: Execute {
internal var explicitTransactionId: TransactionId? { nil }
internal var requiresTransactionId: Bool { true }

internal var firstTransactionId: TransactionId? {
return initialTransactionId
}

internal var index: Int? {
return currentChunk
}

internal var operatorAccountId: AccountId? {
self.transaction.operatorAccountId
}
Expand All @@ -260,16 +270,18 @@ extension ChunkedTransaction.ChunkView: Execute {
) {
assert(transaction.isFrozen)

guard let transactionId = transactionId else {
throw HError.noPayerAccountOrTransactionId
}
let currentTransactionId =
transactionId
?? TransactionId(
accountId: initialTransactionId.accountId,
validStart: initialTransactionId.validStart.adding(nanos: UInt64(currentChunk)))

return transaction.makeRequestInner(
chunkInfo: .init(
current: currentChunk,
total: totalChunks,
initialTransactionId: initialTransactionId,
currentTransactionId: transactionId,
currentTransactionId: currentTransactionId,
nodeAccountId: nodeAccountId
)
)
Expand Down
Loading

0 comments on commit 1f73ffc

Please sign in to comment.