Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop' into feature/addEmptyBytesPublicConstructor
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfridrich authored Jul 7, 2020
2 parents a90b4fb + 0c759e5 commit b3a9d16
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end

target 'Web3Swift_Tests' do
pod 'Web3Swift.io', :path => '../'
pod 'SwiftLint', '~> 0.27'
pod 'SwiftLint', '= 0.27'
pod 'Quick', '~> 1.2'
pod 'Nimble', '~> 7.0'
end
32 changes: 16 additions & 16 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
PODS:
- BigInt (5.0.0)
- CryptoSwift (1.3.0)
- CryptoSwift (1.3.1)
- Nimble (7.3.4)
- Quick (1.3.4)
- secp256k1_ios (0.1.3)
- SwiftLint (0.31.0)
- secp256k1.swift (0.1.4)
- SwiftLint (0.27.0)
- SwiftyJSON (4.3.0)
- Web3Swift.io (0.0.3):
- Web3Swift.io (0.0.4):
- BigInt (~> 5.0)
- CryptoSwift (~> 1.0)
- secp256k1_ios (~> 0.1)
- secp256k1.swift (~> 0.1)
- SwiftyJSON (~> 4.3)

DEPENDENCIES:
- Nimble (~> 7.0)
- Quick (~> 1.2)
- SwiftLint (= 0.27)
- SwiftLint (~> 0.27)
- Web3Swift.io (from `../`)

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- Nimble
- Quick
- SwiftLint
trunk:
- BigInt
- CryptoSwift
- secp256k1_ios
- Nimble
- Quick
- secp256k1.swift
- SwiftLint
- SwiftyJSON

EXTERNAL SOURCES:
Expand All @@ -35,14 +35,14 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8
CryptoSwift: 1283821600233bdbeb96d7b389c3288c3bf77211
CryptoSwift: f12f037f6d0fcd6d48c96db0071b653de64e6c4d
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
Quick: f4f7f063c524394c73ed93ac70983c609805d481
secp256k1_ios: ac9ef04e761f43c58012b28548afa91493761f17
SwiftLint: 7a0227733d786395817373b2d0ca799fd0093ff3
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftLint: 3207c1faa2240bf8973b191820a116113cd11073
SwiftyJSON: 6faa0040f8b59dead0ee07436cbf76b73c08fd08
Web3Swift.io: d73b1a0e4a8cec74493c1090265b7828a5effc48
Web3Swift.io: c10366f6daa98d6cd669d053fbe831b0ed20338d

PODFILE CHECKSUM: 2e44a26eed843b24dadf38c791a6c0a80ffde2fb
PODFILE CHECKSUM: a92dfff1059a074e829f137af158b15e15bc2d87

COCOAPODS: 1.8.4
COCOAPODS: 1.9.3
28 changes: 28 additions & 0 deletions Example/Tests/ContractCall/EthContractCallTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,33 @@ final class EthContractCallTests: XCTestCase {
description: "EOS supply is expected to be 1,000,000,000,000,000,000,000,000,000 wad"
)
}

func testWethDeposit() {
expect{
try HexAsDecimalString(
hex: EthContractCall(
network: MainnetInfuraNetwork(),
senderAddress: EthAddress(
hex: "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990"
),
contractAddress: EthAddress(
hex: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
),
weiAmount: EthNumber(decimal: "1"),
functionCall: EncodedABIFunction(
signature: SimpleString(
string: "deposit()"
),
parameters: []
)
)
).value()
}.to(
equal(
"0"
),
description: "Paypable functions should be eligible for calling"
)
}

}
2 changes: 1 addition & 1 deletion Example/Tests/Entropy/RandomNonceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import CryptoSwift
import Nimble
import Quick
import secp256k1_ios
import secp256k1
@testable import Web3Swift
import XCTest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class EthContractCallBytesTests: XCTestCase {
//TODO: We got a problem with gas price encoding here. Since we use mainnet to encode this request gas price changes every time. Migration to Ganage might solve this problem.
expect{
try EthContractCallBytes(
network: MainnetAlchemyNetwork(),
network: MainnetInfuraNetwork(),
senderKey: Alice().privateKey(),
contractAddress: EthAddress(
hex: "0x6b175474e89094c44da98b954eedeac495271d0f"
Expand Down
4 changes: 2 additions & 2 deletions Example/Tests/TransactionLog/EthTransactionLogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EthTransactionLogTests: XCTestCase {
transactionHash: BytesFromHexString(
hex: "0xfbaad83ca594fa30902586f06c9a2fd4d3855f3769e4cf3157eb0013abd0661f"
),
network: MainnetAlchemyNetwork()
network: MainnetInfuraNetwork()
).receipt().logs().value()[0]

expect{
Expand Down Expand Up @@ -86,7 +86,7 @@ class EthTransactionLogTests: XCTestCase {
expect{
try log.index().value().toDecimalString()
}.to(
equal("0"),
equal("85"),
description: "Expect log index to be correct"
)

Expand Down
10 changes: 5 additions & 5 deletions Example/Web3Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@
"${BUILT_PRODUCTS_DIR}/CryptoSwift/CryptoSwift.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework",
"${BUILT_PRODUCTS_DIR}/Web3Swift.io/Web3Swift.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1_ios/secp256k1_ios.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1.swift/secp256k1.framework",
"${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework",
"${BUILT_PRODUCTS_DIR}/Quick/Quick.framework",
);
Expand All @@ -1086,7 +1086,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CryptoSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Web3Swift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
);
Expand Down Expand Up @@ -1137,7 +1137,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${PODS_ROOT}/SwiftLint/swiftlint --path ../";
shellScript = "${PODS_ROOT}/SwiftLint/swiftlint --path ../\n";
};
D0ECBA0FCDB34E08A91BF630 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -1168,15 +1168,15 @@
"${BUILT_PRODUCTS_DIR}/CryptoSwift/CryptoSwift.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework",
"${BUILT_PRODUCTS_DIR}/Web3Swift.io/Web3Swift.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1_ios/secp256k1_ios.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1.swift/secp256k1.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/BigInt.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CryptoSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Web3Swift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
4 changes: 2 additions & 2 deletions Web3Swift.io.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Web3Swift.io'
s.version = '0.0.3'
s.version = '0.0.4'
s.summary = 'Web3 library for Swift. Construct and sign transactions, interact with smart contracts.'

s.description = <<-DESC
Expand All @@ -23,7 +23,7 @@ encode and decode ABI messages.
s.module_name = 'Web3Swift'
s.source_files = 'Web3Swift/**/*'
s.dependency 'SwiftyJSON', '~> 4.3'
s.dependency 'secp256k1_ios', '~> 0.1'
s.dependency 'secp256k1.swift', '~> 0.1'
s.dependency 'CryptoSwift', '~> 1.0'
s.dependency 'BigInt', '~> 5.0'

Expand Down
1 change: 1 addition & 0 deletions Web3Swift/CollectionScalar/SimpleCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public final class SimpleCollection<T>: CollectionScalar<T> {
- parameters:
- collection: a closure representing an array as a collection of elements
*/
// swiftlint:disable:next attributes
public convenience init(collection: @escaping () throws -> ([T])) {
self.init(collection: { try AnyCollection(collection()) })
}
Expand Down
40 changes: 39 additions & 1 deletion Web3Swift/ContractCall/EthContractCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,44 @@ public final class EthContractCall: BytesScalar {
)
}

/**
Ctor

- parameters:
- network: network to call
- senderAddress: address of the msg.sender
- contractAddress: address of the contract
- weiAmount: amount to be sent in wei
- functionCall: encoded call the contract function
*/
public convenience init(
network: Network,
senderAddress: BytesScalar,
contractAddress: BytesScalar,
weiAmount: BytesScalar,
functionCall: BytesScalar
) {
self.init(
call: ContractCallProcedure(
network: network,
parameters: [
"from" : BytesParameter(
bytes: senderAddress
),
"to" : BytesParameter(
bytes: contractAddress
),
"value" : QuantityParameter(
number: weiAmount
),
"data" : BytesParameter(
bytes: functionCall
)
]
)
)
}

/**
- returns:
The return of the function call
Expand All @@ -103,4 +141,4 @@ public final class EthContractCall: BytesScalar {
return try call.value()
}

}
}
2 changes: 1 addition & 1 deletion Web3Swift/Network/AlchemyNetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class AlchemyNetwork: Network {
- apiKey: api key for accessing JSON RPC calls
*/
public init(chain: String, apiKey: String) {
origin = GethNetwork(url: "https://eth-"+chain.lowercased()+".alchemyapi.io/jsonrpc/"+apiKey)
origin = GethNetwork(url: "https://eth-"+chain.lowercased()+".alchemyapi.io/v2/"+apiKey)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Web3Swift/PrivateKey/EthPrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import CryptoSwift
import Foundation
import secp256k1_ios
import secp256k1

private final class InvalidPrivateKeyError: DescribedError {

Expand Down
2 changes: 1 addition & 1 deletion Web3Swift/SECP256k1/SECP256k1Signature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import CryptoSwift
import Foundation
import secp256k1_ios
import secp256k1

public final class SigningError: DescribedError {

Expand Down
39 changes: 34 additions & 5 deletions Web3Swift/TransactionBytes/EthContractCallBytes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@ public final class EthContractCallBytes: BytesScalar {
contractAddress: BytesScalar,
weiAmount: BytesScalar,
functionCall: BytesScalar
) {
let gasPrice = CachedBytes(
origin: EthGasPrice(
network: network
)
)
self.init(
network: network,
gasPrice: gasPrice,
senderKey: senderKey,
contractAddress: contractAddress,
weiAmount: weiAmount,
functionCall: functionCall
)
}

/**
Ctor

- parameters:
- network: network where transaction is to be deployed
- gasPrice: gas price in Wei
- senderKey: private key of a sender
- contractAddress: address of the recipient contract
- weiAmount: amount to be sent in wei
- functionCall: encoded function call
*/
public convenience init(
network: Network,
gasPrice: BytesScalar,
senderKey: PrivateKey,
contractAddress: BytesScalar,
weiAmount: BytesScalar,
functionCall: BytesScalar
) {
let senderAddress = CachedBytes(
origin: SimpleBytes{
Expand All @@ -75,11 +109,6 @@ public final class EthContractCallBytes: BytesScalar {
let contractAddress = CachedBytes(
origin: contractAddress
)
let gasPrice = CachedBytes(
origin: EthGasPrice(
network: network
)
)
let functionCall = CachedBytes(
origin: functionCall
)
Expand Down
2 changes: 1 addition & 1 deletion Web3Swift/TransactionLogs/EthTransactionLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class EthTransactionLog: TransactionLog {

public func index() throws -> EthNumber {
return try EthNumber(
hex: log["transactionLogIndex"].string()
hex: log["logIndex"].string()
)
}

Expand Down
Loading

0 comments on commit b3a9d16

Please sign in to comment.