2018年 8月 の投稿一覧

Respect/Validation のよくやる設定ミス

Respect/Validationライブラリで数値のチェックを行なっていると、コピペしすぎて0をうまく判定してくれない時がある。

Respect/Validationに「notEmpty」というメソッドがあって
空判定として呼び出していたけど、数値の0はnotEmpty()を通らないので下記のようになってしまう。


$type = 0;

var_dump( Validator::notEmpty()->intVal()->validate( $type ) );
=> False
var_dump( Validator::intVal()->validate( $type ) );
=> True

Cordova ( web3js, infura, ethereumjs-tx.js) でsendSignedTransaction



self.sendTransaction = function( account , toaddress , amountEth ) {
    var   deferred  = $q.defer();
    const amountWei = self.web3.utils.toWei( amountEth , 'ether');

    var tx = {
        from  : account.address,
        to    : toaddress,
        value : amountWei,
    };

    self.web3.eth.estimateGas( tx ).then( ( gasLimit ) => {
        // Gasを前もって仮計算するけど、その瞬間なのでちょっと多めにする。
        tx.gasLimit = self.web3.utils.toHex( gasLimit + 10000 );
        return self.web3.eth.getGasPrice();
    }).then( ( gasPrice ) => {
        // Gasを設定して、nonceを取得(Metamaskでこれが困ったことがあった..)
        tx.gasPrice = self.web3.utils.toHex( gasPrice );
        return self.web3.eth.getTransactionCount( account.address );
    }).then( ( count ) => {
        // 今回は1トランザクションだけど、複数送信の場合は注意
        tx.nonce = count;

        const transaction = new ethereumjs.Tx( tx );
        var privatekey  = account.privateKey;
        // keystoreから復元したら秘密鍵に0xが付いてたけど0xあるとsignで失敗する
        var prefix  = "0x";
        if( privatekey.indexOf( prefix ) === 0 ){
            privatekey = privatekey.slice( prefix.length ) ;
        }
        transaction.sign( ethereumjs.Buffer.Buffer.from( privatekey , 'hex' ) );
        const transactionHex = '0x'+transaction.serialize().toString( 'hex' )
        self.web3.eth.sendSignedTransaction( transactionHex ).once('transactionHash', (hash) => {
                console.log('transaction Hash', 'https://ropsten.etherscan.io/tx/' + hash);
              }).once('receipt', ( receipt ) => {
                console.log('receipt' , receipt );
              })
              .on('confirmation' , (confirmationNumber, receipt) => {
                console.log('confirmation', confirmationNumber, receipt);
              })
              .on('error', console.error );
        });

confirmationをonceにしたから、confirmationずっと流れると思ったけど24で終了した?
解除ってどうやるんだろう、それかonだけにするしかないかな。

OnsenUI2 ons-iconでmd-***してもmaterialデザインのアイコンが表示されない


//出る
<ons-icon icon="md-face"></ons-icon>
//出ない
<ons-icon icon="md-account_circle"></ons-icon>
//出る
<ons-icon icon="md-account-circle"></ons-icon>


勘違いしていました。
こっちだと思っていましたが違いました。
https://material.io/tools/icons/
OnsenUIのマテリアルアイコンはこっちでした。
http://zavoloklom.github.io/material-design-iconic-font/icons.html

と思ってましたが、別のPCでOnsenUIのリファレンス見てたら
やっぱりmaterial.ioへのリンクになってると思って見比べたら

https://ja.onsen.io/v2/api/angular1/ons-icon.html
のMaterial Iconsのリンクは
https://material.io/tools/icons/
だけど
https://onsen.io/v2/api/angular2/ons-icon.html#tutorial
のMaterial Iconsのリンクは
http://zavoloklom.github.io/material-design-iconic-font/icons.html
になってるな、なんだろう。