Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pileks/refactor/simplify templates #1922

Draft
wants to merge 7 commits into
base: origin-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/templates/app/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ dependencies {
// polywrap client
implementation("io.polywrap:polywrap-client:0.10.4")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1")
// polywrap logger plugin
implementation("io.polywrap.plugins:logger:0.10.4")
implementation("com.github.tony19:logback-android:3.0.0")

// ui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,26 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import io.polywrap.client.PolywrapClient
import io.polywrap.configBuilder.polywrapClient
import io.polywrap.plugins.logger.loggerPlugin
import kotlinx.coroutines.launch
import wrap.Ethereum
import wrap.EthereumArgsEncodeParams
import wrap.Logging
import wrap.LoggingArgsLog
import wrap.LoggingLogLevel
import wrap.Sha3
import wrap.Sha3ArgsSha3256

class PolywrapDemoViewModel: ViewModel() {

// we can create a custom client
val loggerInterfaceUri = "wrapscan.io/polywrap/[email protected]"
private val client = polywrapClient {
addDefaults()
setPackage("plugin/logger" to loggerPlugin(null))
addInterfaceImplementation(loggerInterfaceUri, "plugin/logger")
setRedirect(loggerInterfaceUri to "plugin/logger")
}

// and use the custom client to create an SDK class instance
private val logger = Logging(client)
// the client can be shared across SDK instances
private val ethereum = Ethereum(client)

// Because their lifetimes are tied to the client, SDK instances work well as extension properties
val PolywrapClient.eth
get() = ethereum

// or we can create an SDK class instance with a new client using default configuration
private val defaultEth = Ethereum()
private val sha3 = Sha3()

fun polywrapDemo() = viewModelScope.launch {
Log.i("polywrapDemo","Invoking: Logging.info(...)")

logger.log(LoggingArgsLog(LoggingLogLevel.INFO, "Hello there")).getOrThrow()
logger.log(LoggingArgsLog(LoggingLogLevel.INFO, "Hello again")).getOrThrow()
logger.log(LoggingArgsLog(LoggingLogLevel.INFO, "One last time...")).getOrThrow()

Log.i("polywrapDemo","Invoking: Ethereum.encodeParams(...)")

val encodeArgs = EthereumArgsEncodeParams(
types = listOf("address", "uint256"),
values = listOf("0xB1B7586656116D546033e3bAFF69BFcD6592225E", "500")
val sha3Args = Sha3ArgsSha3256(
message = "Hello Polywrap!"
)
val result = client.eth.encodeParams(encodeArgs)
val result = sha3.sha3_256(sha3Args)

if (result.isSuccess) {
println("Ethereum.encodeParams:\n${result.getOrThrow()}")
println("Sha3.sha3_256:\n${result.getOrThrow()}")
} else {
println("Error - Ethereum.encodeParams:\n${result.exceptionOrNull()}")
println("Error - Sha3.sha3_256:\n${result.exceptionOrNull()}")
}
}

Expand All @@ -65,5 +35,3 @@ class PolywrapDemoViewModel: ViewModel() {
defaultEth.client.close()
}
}


3 changes: 1 addition & 2 deletions packages/templates/app/android/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#import * into Logging from "wrapscan.io/polywrap/[email protected]"
#import * into Ethereum from "wrapscan.io/polywrap/[email protected]"
#import * into Sha3 from "wrapscan.io/polywrap/sha3@1"
2 changes: 1 addition & 1 deletion packages/templates/app/android/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
format: 0.4.0
format: 0.5.0
project:
name: Sample
type: app/kotlin
Expand Down
29 changes: 9 additions & 20 deletions packages/templates/app/ios/Template/PolywrapDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@ import UIKit
import PolywrapClient

func polywrapDemo() {
print("Invoking: Logging.info(...)")
print("Invoking: Sha3.sha3_256(...)")

let logger = Logging()
let logArgs = LoggingArgsLog(level: .INFO, message: "Hello there")
try? logger.log(args: logArgs)

// Ethers.encodeParams
print("Invoking: Ethers.encodeParams(...)")

let eth = Ethers()
let encodeArgs = EthersArgsEncodeParams(
types: ["address", "uint256"],
values: ["0xB1B7586656116D546033e3bAFF69BFcD6592225E", "500"]
)
do {
let encoded = try eth.encodeParams(args: encodeArgs)
print("Ethers.encodeParams:\n\(encoded)")
let sha3 = Sha3()
let sha3_256Args = Sha3ArgsSha3256(message: "Hello Polywrap!")

do{
let result = try sha3.sha3_256(args: sha3_256Args)
print("Sha3.sha3_256: \(result)")
} catch {
let logArgs = LoggingArgsLog(level: .ERROR, message: "Error - Ethers.encodeParams: \(error)")
try? logger.log(args: logArgs)
return
print("Error - Sha3.sha3_256: \(error)")
}
}
}
3 changes: 1 addition & 2 deletions packages/templates/app/ios/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#import * into Logging from "wrapscan.io/polywrap/[email protected]"
#import * into Ethers from "wrapscan.io/polywrap/[email protected]"
#import * into Sha3 from "wrapscan.io/polywrap/sha3@1"
2 changes: 1 addition & 1 deletion packages/templates/app/ios/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
format: 0.4.0
format: 0.5.0
project:
name: Sample
type: app/swift
Expand Down
2 changes: 1 addition & 1 deletion packages/templates/app/python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"test": "poetry run python -m sample"
},
"devDependencies": {
"polywrap": "0.11.2"
"polywrap": "0.12.1"
}
}
2 changes: 1 addition & 1 deletion packages/templates/app/python/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#import * into EthersUtils from "wrapscan.io/polywrap/ethers-utils@1"
#import * into Sha3 from "wrapscan.io/polywrap/sha3@1"
2 changes: 1 addition & 1 deletion packages/templates/app/python/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
format: 0.4.0
format: 0.5.0
project:
name: Sample
type: app/python
Expand Down
2 changes: 1 addition & 1 deletion packages/templates/app/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ authors = ["Cesar <[email protected]>", "Niraj <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.10"
polywrap = "^0.1.0b7"
polywrap = "^0.1.2"
4 changes: 2 additions & 2 deletions packages/templates/app/python/sample/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .wrap import EthersUtils
from .wrap import Sha3

__all__ = [
"EthersUtils",
"Sha3",
]
13 changes: 6 additions & 7 deletions packages/templates/app/python/sample/__main__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from .wrap import EthersUtils
from .wrap import Sha3


if __name__ == "__main__":
eth = EthersUtils()
sha3 = Sha3()

print("Invoking: EthersUtils.encodeParams(...)")
print("Invoking: Sha3.sha3_256(...)")

result = eth.encode_params({
"types": ["address", "uint256"],
"values": ["0xB1B7586656116D546033e3bAFF69BFcD6592225E", "500"]
result = sha3.sha3_256({
"message": "Hello Polywrap!"
})

print(f"EthersUtils.encodeParams:\n{result}")
print(f"Sha3.sha3_256:\n{result}")
Loading