HDWalletProvider engine.stop() p = HDWalletProvider(MNEMONIC_SYSTEM, "http://ganache:8545", 0); p.engine.stop(); HDWalletProvider engine.stop() and pool export function GetHdProvider(id: number, rpcurl: string) { //return new HDWalletProvider(MNEMONIC_SYSTEM, url, id); return id==0?Provider1Pool.acquire():Provider2Pool.acquire(); } // Normal use const hdProvider0 = await GetHdProvider(0, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); const hdProvider1 = await GetHdProvider(1, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); // Normal release ReleaseHDProvider1(hdProvider1 ); // Pool code const genericPool = require("generic-pool"); const opts = { max: 10, // maximum size of the pool min: 2, // minimum size of the pool idleTimeoutMillis: 30000, log: true }; const factory0 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 0); }, destroy: function(client) { client.

繼續閱讀

nestjs csrf

https://gitissue.com/repos/jiayisheji/blog pass csrf https://github.com/expressjs/csurf/issues/21 main.ts import { NestFactory } from '@nestjs/core'; import { NestExpressApplication } from '@nestjs/platform-express'; import { join } from 'path' import { AppModule } from './app.module'; import * as cookieSession from 'cookie-session'; import * as helmet from 'helmet'; import * as cookieParser from 'cookie-parser'; import * as csurf from 'csurf'; import * as rateLimit from 'express-rate-limit'; async function bootstrap() { const app = await NestFactory.create( AppModule, ); app.

繼續閱讀

https://gitissue.com/repos/jiayisheji/blog 這網站中的 让我们用Nestjs来重写一个CNode(上、中、下) 幫了大忙,減少大量的浪費時間 =========== html -> jade/pug http://html2jade.aaron-powell.com/ when you html meta want to become jade/pug layout.pug meta(content= csrfToken, name='csrf-token')

繼續閱讀

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.

繼續閱讀

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.

繼續閱讀

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捕捉處理。

繼續閱讀

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.

繼續閱讀

作者的圖片

Sue boy

Sueboy Can support You

CIO

Taiwan