AppCleaner が macOS Mojaveにしたら落ちる。

使ってるバージョンが古かったみたい。
AppCleanerの更新チェックは失敗したので、ダウンロードして上書き

AppCleaner Version 3.0 Beta 2 (3505) → Version 3.4 (3804)


https://freemacsoft.net/appcleaner/
Downloads
Version 3.4
Supports macOS 10.10 to 10.13
Version 2.3
Supports macOS 10.6 to 10.9
Version 1.2.2
Supports macOS 10.4 to 10.5

Elastic CloudにElasticsearchPhpでデータ登録 – Error Content-Type header [application/octet-stream] is not supported


$params = [
    'index' => 'test_index',
    'type'  => 'test_type',
    'id'    => 1,
    'body'  => [ "title" => "タイトルだよ" ]
    ];
$response = $client->index($params);
var_dump( $response );

で実行


$php elastic.php
PHP Fatal error:  Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":"Content-Type header [application/octet-stream] is not supported","status":406} in /Users/dp/ElasticsearchPhp/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:669
Stack trace:

ContentTypeがダメか、Curlの時は注意してましたが、Elasticsearch-PHP [6.0] のマニュアルに指定ってあったかな?

引用:https://dev.classmethod.jp/server-side/elasticsearch/elasticsearch-6-breaking-changes/

Elasticsearch への API は Transport通信を除いて、HTTP(s) リクエストによって操作します。Elasticsearch 5系までは自動検出していた Content-Type ヘッダですが、Elasticsearch 6系より指定が必須となりました。

下記のようにClietにCurlのパラメータ指定を追加してOK


$params = [
    'index' => 'test_index',
    'type'  => 'test_type',
    'id'    => 1,
    'body'  => [ "title" => "タイトルだよ" ]
    'client' => [
        'curl'  => [
            CURLOPT_HTTPHEADER => [
                'Content-type: application/json',
            ]
        ]
    ]
];
$response = $client->index($params);
var_dump( $response );

Elastic CloudにElasticsearchPhpでindex作成メモ


require_once __DIR__ . "/vendor/autoload.php";
use Elasticsearch\ClientBuilder;

$hosts = [[
    'host' => '今回はGCPで作った.us-west1.gcp.cloud.es.io',
    'port' => '9243',
    'scheme' => 'https',
    'user' => 'elastic',
    'pass' => 'elastic cloudで作成時もしくはSecurityから再発行'
    ]];

$client = ClientBuilder::create()->setHosts( $hosts )->build();
$params = [
    'index' => 'test_index'
];
$response = $client->indices()->create( $params );
var_dump( $response );

$php elasticphp.php
array(3) {
  ["acknowledged"]=>
  bool(true)
  ["shards_acknowledged"]=>
  bool(true)
  ["index"]=>
  string(14) "test_index"
}

ブラウザからアクセス


$https://****.us-west1.gcp.cloud.es.io:9243/test_index

{
"test_index": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"creation_date": "1539144639943",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "emZtlTPUsssexa-hgfIr7w",
"version": {
"created": "6040299"
},
"provided_name": "test_index"
}
}
}
}

ElasticsearchにWordPressのRSS/atomを投入するのに初期設定メモ


dp@elasticsearch-1-vm:~$curl -XPUT 'localhost:9200/mytest_index'
{"acknowledged":true,"shards_acknowledged":true,"index":"mytest_index"}
dp@elasticsearch-1-vm:~$ curl -X GET 'localhost:9200/mytest_index?pretty'
{
  "usedoore_index" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1538907897984",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "pAkv7kWAQJKUnxyy91M9PA",
        "version" : {
          "created" : "6040099"
        },
        "provided_name" : "mytest_index"
      }
    }
  }
}

web3.eth.sendSignedTransactionでエラー「 Uncaught (in promise) Error: Returned error: VM Exception while processing transaction: revert」

web3とethereumjs.TxでsendSignedTransactionをコントラクトに送ったところエラーが発生

Uncaught (in promise) Error: Returned error: VM Exception while processing transaction: revert

modifierなどの条件に引っかかっているだけだった。


require( コンディション );

requireは条件がfalseの場合にcontractの処理実行を停止して
contractの状態をトランザクション実行前に戻します。
そして、残ガスを呼び出し元に返却する。
requireは使った分のガスは消費されるので、注意。

truffle migrate でエラー「 Attempting to run transaction which calls a contract function, but recipient address is not a contract address」

TruffleでリモートのGanecheにコントラクトを配置しようとしたらエラーが発生

Error: Attempting to run transaction which calls a contract function, but recipient address 0x***** is not a contract address


dp$ truffle migrate --network development
Compiling ./contracts/TestToken.sol...
Compiling ./contracts/TestTokenCommons.sol...
Compiling openzeppelin-solidity/contracts/math/SafeMath.sol...
Writing artifacts to ./build/contracts

Using network 'development'.

Error: Attempting to run transaction which calls a contract function, but recipient address 0x**************************** is not a contract address
    at Object.InvalidResponse (/Users/dp/.nodebrew/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)

Ganecheをリセットしていたので、キャッシュ的なものがTruffleに残ってる?
削除すれば問題なくGanecheにコントラクトをデプロイできた。


rm -r build/contracts/

Warning: Using contract member “balance” inherited from the address type is deprecated.

Solidityのバージョン変更でコンパイルエラー


contractAdminAddress.transfer( this.balance );

エラー全文


Warning: Using contract member "balance" inherited from the address type is deprecated. Convert the contract to "address" type to access the member, for example use "address(contract).balance" instead.

バージョン変更


- contractAdminAddress.transfer( this.balance );
+ contractAdminAddress.transfer( address( this ).balance );

Warning: Invoking events without “emit” prefix is deprecated.

solidityのバージョンを変えたらWarningがでるようになった。


- pragma solidity ^0.4.18;
+ pragma solidity ^0.4.24;

関数の呼び出しと、イベントの呼び出しを区別するためイベントの場合はemitが必要


Compilation warnings encountered:

/Users/dp/Dropbox/Ethereum/dappsTest/contracts/TestToken.sol:83:3: Warning: Invoking events without "emit" prefix is deprecated.
        Approval( msg.sender , _to , _tokenId );
        ^-------------------------------------^

emit Approval( msg.sender , _to , _tokenId );

https://github.com/ethereum/solidity/issues/2877

Metamaskからエクスポートした秘密鍵をweb3jsとethereumjsでインポートしてみる

EthreumJS


var pk = "0f0ed71771c3cb767ce1eca984f....";// Metamaskからエクスポートした秘密鍵文字列
var pu = ethereumjs.Util.privateToPublic("0x" + pk );

console.log( pu.toString("hex") ); // アドレスがMetamaskと一致

// Metamaskからエクスポートしたまま、Prefixがないとダメ
var pu = ethereumjs.Util.privateToPublic("0x" + pk );
Uncaught RangeError: private key length is invalid
    at Object.exports.isBufferLength (assert.js:31)
    at Object.publicKeyCreate (index.js:61)
    at Object.exports.privateToPublic (index.js:356)
    at :1:25

Web3は秘密鍵のチェックがあまい?


web3  = new Web3();

var pk = "0f0ed71771c3cb767ce1eca984f....";// Metamaskからエクスポートした秘密鍵文字列

var account = web3.eth.accounts.privateKeyToAccount( pk );

console.log( accoun );
{address: "0x6C0(Metamaskと違う)", privateKey: "0f0ed71771c3cb767ce1eca984f....", signTransaction: ƒ, sign: ƒ, encrypt: ƒ}

// Metamaskからエクスポートしたまま、Prefixがないとダメ
var account = web3.eth.accounts.privateKeyToAccount( "0x" + pk );

console.log( accoun );
{address: "0xa43d0(Metamaskと一致)", privateKey: "0x0f0ed71771c3cb767ce1eca984f....", signTransaction: ƒ, sign: ƒ, encrypt: ƒ}

ファイルによって「 Invalid JSON RPC response」なんて言われるから
通信してるかと思ったけど、よく調べたらmetamaskが提供してくれるweb3.jsと
自分がローカルで使ってるweb3.jsが結構違ったのでメモ

https://github.com/MetaMask/metamask-extension/blob/develop/package.json
Metamaskの提供してくれるweb3ではaccounts系は提供されていません。


var account = web3.eth.accounts.privateKeyToAccount( "0x" + pk );
inpage.js:1 Uncaught Error: Invalid JSON RPC response: undefined
    at Object.InvalidResponse (inpage.js:1)
    at s.send (inpage.js:1)
    at n.accounts (inpage.js:1)
    at :1:15

web3-1.0系だとprivateKeyToAccountがあります。

https://raw.githubusercontent.com/ethereum/web3.js/v1.0.0-beta.35/dist/web3.js


Accounts.prototype.create = function create(entropy) {
    return this._addAccountFunctions(Account.create(entropy || utils.randomHex(32)));
};
Accounts.prototype.privateKeyToAccount = function privateKeyToAccount(privateKey) {
    return this._addAccountFunctions(Account.fromPrivate(privateKey));
};
Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, callback) {

Windows8タブレット( 64bitなのにUEFIが32bit )にUbuntu18のインストール

macOSXでubuntuとdebianのisoから必要なファイルをUSBにコピーするのですが
iosはMacでマウントできないといわれたので、hdiutilをつかってマウントする。


$ hdiutil attach -nobrowse -nomount debian-9.5.0-amd64-i386-netinst.iso
/dev/disk3              Apple_partition_scheme
/dev/disk3s1            Apple_partition_map
/dev/disk3s2            Apple_HFS
$ mount -t cd9660 /dev/disk3 debian

windowsタブレットはUSBポートが少ないので
USBハブにUSBメモリ、マウス、キーボードをつけて
BIOSメニューからまずは、secureBootの無効化をして起動順を設定しますが、それだと起動しなかったので、Save & ExitにあるBoot OverrideからUSBを指定して起動

USBデバイスがBlk数字としては認識してるけど
fs数字になっていない。。
UEFIのシェルからUSBのBlkをマウントしても中身がみえない。。


mount blk5 usb5
usb5:
ls

Pcirootからのところをよく見ると
USBがGPTじゃなくてMBRになっていました。
USBメモリをフォーマットするときに選択ミスしていたみたい。


map fs*
map blk*