truffle truffle-hdwallet-provider Error: Error: the tx doesn't have the correct nonce. account has nonce of: 3 tx has nonce of: 2

What this Error? Example: transaction A get nonce 1 transaction B get nonce 2 transaction C get nonce 3 But blockchain package B、C first, then package A. If happen this step, get error. With truffle? Because Normal const wallet = new HDWalletProvider(mnemonic, url, id); const AContract = new TruffleContract(Json_contract); AContract.setProvider(wallet); wallet.addresses[] AContract. use contract api Sometime you call contract “set/write” api two times. Example: Create contract first. Write data into contract second. This two step are in one function. This mean is you call two time “new HDWalletProvide”. Usually you think “New“ two time is ok, get “new” instance. But ...

2019-05-21 · 1 min · 134 words · Me

[???]nestjs Cross modules dependency injection

import module providers service So if you want use some controllers(this controllers is in some module), this time need to import module. ???? =========== https://github.com/zelazna/NestAPI/tree/master/src Impotant: constructor don’t use new(). Use this.usersService. src/auth/auth.service.ts import { Component } from '@nestjs/common'; import { UsersService } from '../users'; @Component() ?? Injectable export class AuthService { constructor( private readonly usersService: UsersService, ) { } async validateUser(signedUser): Promise { const { email, password } = signedUser; const user = await this.usersService.findOneByEmail(email); return await EncryptorService.validate(password, user.password); } Impotant: exports need UsersService ...

2019-05-13 · 1 min · 102 words · Me

[轉]Nestjs framework 30天初探:Day30 總結Nest.js

https://ithelp.ithome.com.tw/articles/10195523 Controller,透過Nest.js把metadata映射到我們自定義的route,Nest.js本身也有提供很多裝飾器,而且是對應Express框架,讓我們可以更好上手,更容易了解Controller層,可以寫出很Express風格的Controller。 Component,Nest.js裏頭很多東西都是Component,如:Service,Repository,Factory,Helper…,再透過依賴注入的方式,將Component注入到其他地方使用。 Module,Module是Nest.js專案的根基,Nest.js可以寫出Module tree風格的專案,Component可以注入到Module,如此,該Module底下的Controller和Component就屬同作用域,然後就可以依賴注入使用該Component。 Middleware,用Express框架的朋友應該不陌生,這概念雷同,在程式處理請求前,我們可以做些事情,這就是Middleware的功用,但要記得要調用next(),不然程式會卡在那XD,導入Middleware的方式上跟Express略有不同,多注意一下就好。 Exception Filter,錯誤處理層其實還蠻常使用,統一格式回給Client端或進行錯誤Log處理,這都蠻重要。我們可以繼承HttpException,做一個客製化的HttpException回應給Client,也可以繼承ExceptionFilter,做更多的錯誤處理(如Log)。 Pipe,Pipe可以將input data轉換成我們想要的output data,它也可以扛下參數資料驗證工作,在參數資料不正確時拋HttpException出來,這個錯誤會被ExceptionsHandler或自定義的Exception Filter所捕捉。 Guard,Guard就是擔任路由警衛,決定程式在收到HTTP請求後,是否要執行 route handler。 注意:客戶發動請求的流程為 Request->Middleware->Guard->Pipe->route handler。 Interceptor,我們可以透過Interceptor做些事情,像在請求前,完整記錄post過來的data,或在給予Client回應前,攔截一下,做些處理再返回,另外Interceptor 拋出的錯誤仍然可以被Exception Filter捕捉處理。

2019-05-10 · 1 min · 21 words · Me

[轉]2018 年了,你还是只会 npm install 吗?

https://juejin.im/post/5ab3f77df265da2392364341 本地模块引用 這段不錯

2019-05-08 · 1 min · 3 words · Me

nest.js 是 nodejs 服务运行时,要等待数据库服务启动完毕,也就是有一个启动等待的需求

https://juejin.im/entry/59a6325d6fb9a024932228e0 version: "2" services: app: build: ./ restart: always ports: - "5000:8000" links: - db - redis depends_on: - db - redis environment: WAIT_HOSTS: db:3306 redis:6379 CMD ./scripts/docker/wait-for.sh && npm run deploy #!/bin/bash set -e timeout=${WAIT_HOSTS_TIMEOUT:-30} waitAfterHosts=${WAIT_AFTER_HOSTS:-0} waitBeforeHosts=${WAIT_BEFORE_HOSTS:-0} echo "Waiting for ${waitBeforeHosts} seconds." sleep $waitBeforeHosts # our target format is a comma separated list where each item is "host:ip" if [ -n "$WAIT_HOSTS" ]; then uris=$(echo $WAIT_HOSTS | sed -e 's/,/ /g' -e 's/\s+/\n/g' | uniq) fi # wait for each target if [ -z "$uris" ]; then echo "No wait targets found." >&2; else for uri in $uris do host=$(echo $uri | cut -d: -f1) port=$(echo $uri | cut -d: -f2) [ -n "${host}" ] [ -n "${port}" ] echo "Waiting for ${uri}." seconds=0 while [ "$seconds" -lt "$timeout" ] && ! nc -z -w1 $host $port do echo -n . seconds=$((seconds+1)) sleep 1 done if [ "$seconds" -lt "$timeout" ]; then echo "${uri} is up!" else echo " ERROR: unable to connect to ${uri}" >&2 exit 1 fi done echo "All hosts are up" fi echo "Waiting for ${waitAfterHosts} seconds." sleep $waitAfterHosts exit 0

2019-05-08 · 1 min · 186 words · Me