Dart await keyword - dart-async

I want to try the rpc package of Dart using the io sample (https://github.com/dart-lang/rpc)
I'm on the 64 bits version of Dart editor with the 1.9.1 sdk (cannot update more thans stable version)
This is my pubspec.yaml :
name: myDartRestServer
version: 0.0.1
description: A minimal command-line application.
#author: <your name> <email#example.com>
#homepage: https://www.example.com
environment:
sdk: '1.9.1'
dependencies:
rpc: any
dev_dependencies:
unittest: any
But when I try to copy the sample for launch my server :
final ApiServer _apiServer = new ApiServer('/api/', prettyPrint: true);
void start() {
_apiServer.addApi(new Synchro());
HttpServer server = await HttpServer.bind(InternetAddress.ANY_IP_V4, 9090);
server.listen(_apiServer.httpRequestHandler);
_apiServer.enableDiscoveryApi("http://localhost:9090");
}
My EDI(SDK) don't know the await keyword. (I import the dart:io dart:async and rpc package in my library file)
I've missed something? Thanks by advance for your responses. Have a nice day.

You need to mark the function as async in order to be able to use await
void start() async {
....
try at DartPad
Without async await is a valid identifier.

Related

How to include what's being defined in the defining variable?

Good day, I have a question. I have here a function that doesn't give me Client with a valid manager. Here's the function:
function SetupClient(user) {
let Client = {
client: new SteamUser(),
community: new SteamCommunity(),
manager: new TradeOfferManager({
steam: this.client,
community: this.community,
language: 'en'
}),
details: user
}
SteamClients[user.username] = Client;
Debug.emit('message', `Client setup: ${SteamClients[user.username]}`);
}
I am trying to get the client that is being created as it's being created... I guess? Hope my intentions are shown in the code accurately.
I messed up, this works, I just called community, instead of calling it as a property of Client. Oops...

Write An azure function with Javascript that is connecting OracleDB and running on Docker

I have an Azure Function that is written with Visual Studio Code and it is a nodejs application with javascript codes.
Also, the application connects to Oracle DB to run an Oracle Script.
Also, the application runs on a Docker image.
I added the npm packages for oracle connection;
npm i express
npm i oracledb
Below my some key points of code;
Dockerfile
FROM mcr.microsoft.com/azure-functions/node:3.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
RUN cd /home/site/wwwroot && \
npm install
index.js
module.exports = async function (context, req) {
let responseMessage = "";
let connection;
try {
const oracledb = require('oracledb');
connection = await oracledb.getConnection({
user: "xx",
password: "xx",
connectString: req.body
});
let query = 'select * from xx where rownum=1';
result = await connection.execute(query);
responseMessage = result;
} catch (err) {
responseMessage = err.message;
} finally {
if (connection) {
try {
// Always close connections
await connection.close();
} catch (err) {
responseMessage = err.message;
}
}
}
context.res = {
body: responseMessage
};
}
Here is my folder structure of project;
CASE1: When I run the project with "func start" the application is working properly and gets the result.
CASE2: When I run it on my local docker with below steps it returns an error form HTTP response.
Run "docker build ."
docker run -d -p 99:80 myimage
It is listed on "docker ps" list.
I call the endpoint "http://localhost:99/api/HttpExample" I get an error.
DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/node-oracledb/INSTALL.html for help
Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
You must have 64-bit Oracle client libraries in LD_LIBRARY_PATH, or configured with ldconfig.
If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
I search some documentations but I can't find the solution for especially Azure Function Project. Because my dockerfile have to be created based on "FROM mcr.microsoft.com/azure-functions/node:3.0".
What should be the Dockerfile for this project?

Is there a redis package for "Azure cache for Redis" in dart 2.9.2 (for flutter app) which takes hostname, port and its key in the connection string?

I want to connect my Azure Cache for Redis in a flutter app. Currently I've tried two packages in dart for redis which are redis 1.3.0 and dartis 0.5.0.
Example:
import 'package:redis/redis.dart';
...
RedisConnection conn = new RedisConnection();
conn
.connect('localhost', 6379)
.then((Command command) {
print("yo2");
command.send_object(["SET", "key1", "value1"]).then((var response) {
print(response);
});
});
Instead of "localhost" I put "SampleName.redis.cache.windows.net". This is the error I get:
E/flutter ( 4861): [ERROR:flutter/shell/common/shell.cc(209)] Dart Error: Unhandled exception:
E/flutter ( 4861): RedisError(NOAUTH Authentication required.)
old package This is the package starred on Redis Website. But it's incompatible on versions >2.
Okay so I found the solution. Use your key in the following way:
For redis 1.3.0:
...
RedisConnection conn = new RedisConnection();
conn
.connect('SampleName.redis.cache.windows.net', 6379)
.then((Command command) {
print("yo2");
command.send_object([
"AUTH",
"<YourKey>"
]).then((var response) {
print(response);
});
command.send_object(["SET", "key1", "value1"]);
});
...
And for dartis 0.5.0:
...
final client = await redis.Client.connect(
'redis://SampleName.redis.cache.windows.net:6379');
// Runs some commands.
final commands = client.asCommands<String, String>();
await commands.auth("<YourKey>");
// SET key value
await commands.set('yo', 'yovalue');
...

UnhandledPromiseRejectionWarning: Error: The contract code couldn't be stored, please check your gas limit

I am trying to deploy my simple solidity smart contract onto the Rinkeby Network but I keep getting the error:
UnhandledPromiseRejectionWarning: Error: The contract code couldn't be
stored, please check your gas limit.
My solidity code is simple
pragma solidity ^0.4.18;
contract Greetings{
string public message;
function Greetings(string initialMessage) public{
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
and my deploy script is:
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface,bytecode} = require('./compile');
const provider = new HDWalletProvider(
'twelve word mnemonic...',
'https://rinkeby.infura.io/GLm6McXWuaih4gqq8nTY'
);
const web3 = new Web3(provider);
const deploy = async () => {
accounts = await web3.eth.getAccounts();
console.log('attempting to deploy from account',accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data:bytecode, arguments:['Hello World']})
.send({from: accounts[0], gas:'1000000'});
console.log('Contract deployed to', result.options.address);
};
deploy();
Funny thing is, I used to be able to deploy successfully, but when i created a new project and re did the same code, i get this error now. Please help!
Had exactly same problem! Seems it is caused by the bug in the "truffle-hdwallet-provider" version 0.0.5. During the udemy course it was using "0.0.3" apparently.
If you do the following should be okay, it worked for me.
npm uninstall truffle-hdwallet-provider
npm install --save truffle-hdwallet-provider#0.0.3
Then I ran the same contract which has deployed successfully.
Good luck!
This issue can be solved by adding the '0x' as the prefix of the bytecode:
.deploy({ data: '0x' + bytecode, arguments: ['Hi there!'] })
More information is at https://ethereum.stackexchange.com/a/47654.
I believe bytecode is being treated as a single number rather than a series of bytes. Instead of submitting data:bytecode, try:
data:'0x0' + bytecode
it will "preserve" bytecode value as a string
Also just remove the gas field let metamask decide the gas limit. this way works for me.

CryptoSwift: unresolved identifier 'GCM'

xcode version: 9.3.1 (9E145)
Swift version: 4.1
I have just downloaded the latest master copy and installed CryptoSwift using CocoaPods. Using the example given on the README:
do {
// In combined mode, the authentication tag is directly appended to the encrypted message. This is usually what you want.
let gcm = GCM(iv: iv, mode: .combined)
let aes = try AES(key: key, blockMode: gcm, padding: .noPadding)
let encrypted = try aes.encrypt(plaintext)
let tag = gcm.authenticationTag
catch {
// failed
}
I get the error of "Use of unresolved identifier 'GCM'". I have tried other functions like aes.encrypt and aes.decrypt and they all work fine
GCM is a part of Crypto Swift so you should import Crypto swift that's what is missing i think so import it first in your controller
import CryptoSwift

Resources