EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/

smart contract storage struct 未初始化 直接使用問題

https://github.com/knownsec/Ethereum-Smart-Contracts-Security-CheckList/blob/master/%E4%BB%A5%E5%A4%AA%E5%9D%8A%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6%E5%AE%A1%E8%AE%A1CheckList.md#11-%E6%9C%AA%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E5%82%A8%E5%AD%98%E6%8C%87%E9%92%88

https://www.chaindd.com/3102377.html

https://blog.b9lab.com/storage-pointers-in-solidity-7dcfaa536089

https://medium.com/loom-network/ethereum-solidity-memory-vs-storage-how-to-initialize-an-array-inside-a-struct-184baf6aa2eb

Use delete or new

web3 deploy smart contract 1.2.1

Use https://remix.ethereum.org Get Contract json and data.


In remix website, Compile finish. See Compliation Details.


1. ABI: click ABI buttion, get data. Use http://jsonviewer.stack.hu/ remove space

2. Compliation Details -> WEB3DEPLOY -> get data


3. cContract.options.from need put correct.


var Web3 = require("web3");
var provider = new Web3.providers.HttpProvider("http://ganache:8545");
var web3 = new Web3(provider);

//abi
var cContract = new web3.eth.Contract([{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}])

//bytecode
cContract.options.data = '0x608060405234801561001057600080fd5b5060bf8061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166360fe47b18114604d5780636d4ce63c146064575b600080fd5b348015605857600080fd5b5060626004356088565b005b348015606f57600080fd5b506076608d565b60408051918252519081900360200190f35b600055565b600054905600a165627a7a72305820765480c908e5e28e3233e18bfa422944b42cad5fc08b77d7b22d3ddd7016a1380029'

cContract.options.from = '0xoooxxxoooxxxoooxxxoooxxxoooxxx'
cContract.options.gas = '4700000'

console.log("web3 version: %o", web3.version)
web3.eth.getAccounts().then(o=>{console.log(o)})

cContract.deploy().send()
.on('error', (error) => {
    console.log("error: %o", error)
})
.on('transactionHash', (transactionHash) => {
    console.log("transactionHash: %o", transactionHash)
})
.on('receipt', (receipt) => {
    // receipt will contain deployed contract address
    console.log("receipt: %o", receipt)
    console.log("receipt.contractAddress: %o", receipt.contractAddress) 
})
.on('confirmation', (confirmationNumber, receipt) => {
    console.log("confirmationNumber: %o", confirmationNumber)
    console.log("confirmation receipt: %o", receipt)
})
.then(function(newContractInstance){
    if (typeof newContractInstance.options.address !== 'undefined') {
        console.log('Contract mined! address: ' + newContractInstance.options.address);
    }else{
        console.log("newContractInstance.address is undefined!")
    }
});

HDWalletProvider web3 smart contract connection need to stop or pool

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.engine.stop();
  }
};

const factory1 = {  // maybe different parms
  create: function() {
    return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 1);
  },
  destroy: function(client) {
    client.engine.stop();
  }
};

export function ReleaseHDProvider1(client){
  Provider1Pool.release(client);
  console.log("Provider1Pool status: pool.size %o pool.available %o pool.pending %o", Provider1Pool.size, Provider1Pool.available, Provider1Pool.pending)
}

export function ReleaseHDProvider2(client){
  Provider2Pool.release(client);
  console.log("Provider2Pool status: pool.size %o pool.available %o pool.pending %o", Provider2Pool.size, Provider2Pool.available, Provider2Pool.pending)
}

const Provider1Pool = genericPool.createPool(factory0, opts);
const Provider2Pool = genericPool.createPool(factory1, opts);