您正在查看: 2018年7月

EOS traces 多个相同的 txid数据

{
    "id": "fe804e9a9ab2a9f8b674bb490ac2c89d4f70247f82bc506adc7285cb82e3c991",
    "trx": {
        "receipt": {
            "status": "executed",
            "cpu_usage_us": 688,
            "net_usage_words": 16,
            "trx": [
                1,
                {
                    "signatures": [
                        "SIG_K1_KUypLM5YSdRRZMTuTDUAu4fr4V3FhabKJdGdNcZTaTj5zbsB1xfta3FvL5XEGkaduako2yVaHhQxLc5hm8TjpmGarXDRoM"
                    ],
                    "compression": "none",
                    "packed_context_free_data": "",
                    "packed_trx": "d27c555bc5a54ba71421000000000100a6823403ea3055000000572d3ccdcd0130c618630c05a77900000000a8ed32322130c618630c05a77990b1cadec45aab49204e00000000000004454f53000000000000"
                }
            ]
        },
        "trx": {
            "expiration": "2018-07-23T06:59:30",
            "ref_block_num": 42437,
            "ref_block_prefix": 555001675,
            "max_net_usage_words": 0,
            "max_cpu_usage_ms": 0,
            "delay_sec": 0,
            "context_free_actions": [],
            "actions": [
                {
                    "account": "eosio.token",
                    "name": "transfer",
                    "authorization": [
                        {
                            "actor": "bcskill3333333",
                            "permission": "active"
                        }
                    ],
                    "data": {
                        "from": "bcskill3333333",
                        "to": "dappplaytest",
                        "quantity": "2.0000 EOS",
                        "memo": ""
                    },
                    "hex_data": "30c618630c05a77990b1cadec45aab49204e00000000000004454f530000000000"
                }
            ],
            "transaction_extensions": [],
            "signatures": [
                "SIG_K1_KUypLM5YSdRRZMTuTDUAu4fr4V3FhabKJdGdNcZTaTj5zbsB1xfta3FvL5XEGkaduako2yVaHhQxLc5hm8TjpmGarXDRoM"
            ],
            "context_free_data": []
        }
    },
    "block_time": "2018-07-23T06:58:32.000",
    "block_num": 7317258,
    "last_irreversible_block": 8006080,
    "traces": [
        {
            "receipt": {
                "receiver": "eosio.token",
                "act_digest": "c6c9aa38acd0c3940de511b6ee69b1831f047f895b4aa94a6cde8ae80dfdd6a5",
                "global_sequence": 74737287,
                "recv_sequence": 2145761,
                "auth_sequence": [
                    [
                        "bcskill3333333",
                        6
                    ]
                ],
                "code_sequence": 1,
                "abi_sequence": 1
            },
            "act": {
                "account": "eosio.token",
                "name": "transfer",
                "authorization": [
                    {
                        "actor": "bcskill3333333",
                        "permission": "active"
                    }
                ],
                "data": {
                    "from": "bcskill3333333",
                    "to": "dappplaytest",
                    "quantity": "2.0000 EOS",
                    "memo": ""
                },
                "hex_data": "30c618630c05a77990b1cadec45aab49204e00000000000004454f530000000000"
            },
            "elapsed": 42,
            "cpu_usage": 0,
            "console": "",
            "total_cpu_usage": 0,
            "trx_id": "fe804e9a9ab2a9f8b674bb490ac2c89d4f70247f82bc506adc7285cb82e3c991",
            "inline_traces": [
                {
                    "receipt": {
                        "receiver": "bcskill3333333",
                        "act_digest": "c6c9aa38acd0c3940de511b6ee69b1831f047f895b4aa94a6cde8ae80dfdd6a5",
                        "global_sequence": 74737288,
                        "recv_sequence": 19,
                        "auth_sequence": [
                            [
                                "bcskill3333333",
                                7
                            ]
                        ],
                        "code_sequence": 1,
                        "abi_sequence": 1
                    },
                    "act": {
                        "account": "eosio.token",
                        "name": "transfer",
                        "authorization": [
                            {
                                "actor": "bcskill3333333",
                                "permission": "active"
                            }
                        ],
                        "data": {
                            "from": "bcskill3333333",
                            "to": "dappplaytest",
                            "quantity": "2.0000 EOS",
                            "memo": ""
                        },
                        "hex_data": "30c618630c05a77990b1cadec45aab49204e00000000000004454f530000000000"
                    },
                    "elapsed": 3,
                    "cpu_usage": 0,
                    "console": "",
                    "total_cpu_usage": 0,
                    "trx_id": "fe804e9a9ab2a9f8b674bb490ac2c89d4f70247f82bc506adc7285cb82e3c991",
                    "inline_traces": []
                },
                {
                    "receipt": {
                        "receiver": "dappplaytest",
                        "act_digest": "c6c9aa38acd0c3940de511b6ee69b1831f047f895b4aa94a6cde8ae80dfdd6a5",
                        "global_sequence": 74737289,
                        "recv_sequence": 1,
                        "auth_sequence": [
                            [
                                "bcskill3333333",
                                8
                            ]
                        ],
                        "code_sequence": 1,
                        "abi_sequence": 1
                    },
                    "act": {
                        "account": "eosio.token",
                        "name": "transfer",
                        "authorization": [
                            {
                                "actor": "bcskill3333333",
                                "permission": "active"
                            }
                        ],
                        "data": {
                            "from": "bcskill3333333",
                            "to": "dappplaytest",
                            "quantity": "2.0000 EOS",
                            "memo": ""
                        },
                        "hex_data": "30c618630c05a77990b1cadec45aab49204e00000000000004454f530000000000"
                    },
                    "elapsed": 5,
                    "cpu_usage": 0,
                    "console": "",
                    "total_cpu_usage": 0,
                    "trx_id": "fe804e9a9ab2a9f8b674bb490ac2c89d4f70247f82bc506adc7285cb82e3c991",
                    "inline_traces": []
                }
            ]
        },
        {
            "receipt": {
                "receiver": "bcskill3333333",
                "act_digest": "c6c9aa38acd0c3940de511b6ee69b1831f047f895b4aa94a6cde8ae80dfdd6a5",
                "global_sequence": 74737288,
                "recv_sequence": 19,
                "auth_sequence": [
                    [
                        "bcskill3333333",
                        7
                    ]
                ],
                "code_sequence": 1,
                "abi_sequence": 1
            },
            "act": {
                "account": "eosio.token",
                "name": "transfer",
                "authorization": [
                    {
                        "actor": "bcskill3333333",
                        "permission": "active"
                    }
                ],
                "data": {
                    "from": "bcskill3333333",
                    "to": "dappplaytest",
                    "quantity": "2.0000 EOS",
                    "memo": ""
                },
                "hex_data": "30c618630c05a77990b1cadec45aab49204e00000000000004454f530000000000"
            },
            "elapsed": 3,
            "cpu_usage": 0,
            "console": "",
            "total_cpu_usage": 0,
            "trx_id": "fe804e9a9ab2a9f8b674bb490ac2c89d4f70247f82bc506adc7285cb82e3c991",
            "inline_traces": []
        },
        {
            "receipt": {
                "receiver": "dappplaytest",
                "act_digest": "c6c9aa38acd0c3940de511b6ee69b1831f047f895b4aa94a6cde8ae80dfdd6a5",
                "global_sequence": 74737289,
                "recv_sequence": 1,
                "auth_sequence": [
                    [
                        "bcskill3333333",
                        8
                    ]
                ],
                "code_sequence": 1,
                "abi_sequence": 1
            },
            "act": {
                "account": "eosio.token",
                "name": "transfer",
                "authorization": [
                    {
                        "actor": "bcskill3333333",
                        "permission": "active"
                    }
                ],
                "data": {
                    "from": "bcskill3333333",
                    "to": "dappplaytest",
                    "quantity": "2.0000 EOS",
                    "memo": ""
                },
                "hex_data": "30c618630c05a77990b1cadec45aab49204e00000000000004454f530000000000"
            },
            "elapsed": 5,
            "cpu_usage": 0,
            "console": "",
            "total_cpu_usage": 0,
            "trx_id": "fe804e9a9ab2a9f8b674bb490ac2c89d4f70247f82bc506adc7285cb82e3c991",
            "inline_traces": []
        }
    ]
}

traces里面的你可以理解为是给参与这次交易的各个角色的发票清单 每一次EOS的转账都涉及到3个角色:转账方、接受方、执行转账操作的token发行方,如果是收款方查到的只是其中一个

EOS 新建账户合约,转账到执行账户,创建账户

查看主要代码

//signdappplay.cpp

#include "signdappplay.hpp"

void signdappplay::transfer(account_name from, account_name to, asset quantity, string memo)
{
    if (from == _self || to != _self) {
        return;
    }

    // don't do anything on transfers from our reference account
    if (from == N(signdappplay)) {
      return;
    }

    eosio_assert(quantity.symbol == CORE_SYMBOL, "only core token allowed"); //string_to_symbol(4, "EOS")
    eosio_assert(quantity.is_valid(), "Invalid token transfer");
    eosio_assert(quantity.amount > 0, "Quantity must be positive");

    //memo "your_account_name-your_owner_public_key-your_active_public_key" 分隔符支持“-” “:” 空格
    //去掉memo前面的空格
    memo.erase(memo.begin(), find_if(memo.begin(), memo.end(), [](int ch) {
        return !isspace(ch);
    }));
    //去掉memo后面的空格
    memo.erase(find_if(memo.rbegin(), memo.rend(), [](int ch) {
        return !isspace(ch);
    }).base(), memo.end());

    eosio_assert(memo.length() == 120 || memo.length() == 66, "Malformed Memo (not right length)");
    const string account_string = memo.substr(0, 12);
    const account_name new_account_name = string_to_name(account_string.c_str());
    eosio_assert(memo[12] == ':' || memo[12] == '-' || memo[12] == ' ', "Malformed Memo [12] == : or - or space");

    const string owner_key_str = memo.substr(13, 53);
    string active_key_str;

    if(memo[66] == ':' || memo[66] == '-' || memo[66] == ' ') {
      // active key provided
      active_key_str = memo.substr(67, 53);
    } else {
      // active key is the same as owner
      active_key_str = owner_key_str;
    }

    const abieos::public_key owner_pubkey =
        abieos::string_to_public_key(owner_key_str);
    const abieos::public_key active_pubkey =
        abieos::string_to_public_key(active_key_str);

    array<char, 33> owner_pubkey_char;
    copy(owner_pubkey.data.begin(), owner_pubkey.data.end(),
         owner_pubkey_char.begin());

    array<char, 33> active_pubkey_char;
    copy(active_pubkey.data.begin(), active_pubkey.data.end(),
         active_pubkey_char.begin());

    key_weight owner_pubkey_weight = {
        .key = {0, owner_pubkey_char},
        .weight = 1
    };

    key_weight active_pubkey_weight = {
        .key = {0, owner_pubkey_char},
        .weight = 1
    };

    authority owner = authority{
        .threshold = 1,
        .keys = {owner_pubkey_weight},
        .accounts = {},
        .waits = {}
    };

    authority active = authority{
        .threshold = 1,
        .keys = {active_pubkey_weight},
        .accounts = {},
        .waits = {}
    };

    newaccount new_account = newaccount{
        .creator = _self,
        .name = new_account_name,
        .owner = owner,
        .active = active
    };

    asset stake_net(1000, CORE_SYMBOL);
    asset stake_cpu(1000, CORE_SYMBOL);
    asset buy_ram = quantity - stake_net - stake_cpu;
    eosio_assert(buy_ram.amount > 0, "Not enough balance to buy ram");

    // create account
    action(
            permission_level{ _self, N(active) },
            N(eosio),
            N(newaccount),
            new_account
    ).send();
    // buy ram
    action(
            permission_level{ _self, N(active)},
            N(eosio),
            N(buyram),
            make_tuple(_self, new_account_name, buy_ram)
    ).send();
    // delegate and transfer cpu and net
    action(
            permission_level{ _self, N(active)},
            N(eosio),
            N(delegatebw),
            make_tuple(_self, new_account_name, stake_net, stake_cpu, true)
    ).send();
}

开始部署

  • 下载代码
    git clone https://github.com/cppfuns/signdappplay.git
  • 编译代码
    //进入源码目录
    cd signdappplay/
    //生成abi文件
    eosiocpp -g signdappplay.abi signdappplay.cpp
    //生成wast文件
    eosiocpp -o signdappplay.wast signdappplay.cpp
  • 部署合约
    //提前创建好signdappplay 将合约部署到此账号
    cleos set contract signdappplay signdappplay/ -p signdappplay
  • signdappplay@active里添加signdappplay@eosio.code授权
    cleos set account permission signdappplay active '{"threshold": 1,"keys": [{"key": "EOS7nK2w6ZT8hKdrxr48xdt3CFj1MXpaDV6jagRHKayFhqJBX5GEf","weight": 1}],"accounts": [{"permission":{"actor":"signdappplay","permission":"eosio.code"},"weight":1}]}' owner -p signdappplay

开始转账创建账号

signdappplay账号转账,并按规则(新建账户名:owner公钥:active公钥)填写memo。(分隔符支持"-" ":"或者空格,如果owner公钥与active公钥一致,可以只填写一个,如实例)。

root@iZj6cbx3duprxf6dasczbpZ:~# cleos push action eosio.token transfer '["dapp.exec", "signdappplay","100.0000 EOS","dingtet12345:EOS8Hdw6vismBgoYPzfLhr2rtHrdsR3F8UYAL23LSc9wdV8eNhNH8"]' -p dapp.exec
executed transaction: e6d94f39de7e6508e06b469327eb63eb6100ce129deb152a484acc0399bae292  192 bytes  12152 us
#   eosio.token <= eosio.token::transfer        {"from":"dapp.exec","to":"signdappplay","quantity":"100.0000 EOS","memo":"dingtet12345:EOS8Hdw6vismB...
#     dapp.exec <= eosio.token::transfer        {"from":"dapp.exec","to":"signdappplay","quantity":"100.0000 EOS","memo":"dingtet12345:EOS8Hdw6vismB...
#  signdappplay <= eosio.token::transfer        {"from":"dapp.exec","to":"signdappplay","quantity":"100.0000 EOS","memo":"dingtet12345:EOS8Hdw6vismB...
#         eosio <= eosio::newaccount            {"creator":"signdappplay","name":"dingtet12345","owner":{"threshold":1,"keys":[{"key":"EOS8Hdw6vismB...
#         eosio <= eosio::buyram                {"payer":"signdappplay","receiver":"dingtet12345","quant":"99.8000 EOS"}
#   eosio.token <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.ram","quantity":"99.3010 EOS","memo":"buy ram"}
#  signdappplay <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.ram","quantity":"99.3010 EOS","memo":"buy ram"}
#     eosio.ram <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.ram","quantity":"99.3010 EOS","memo":"buy ram"}
#   eosio.token <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.ramfee","quantity":"0.4990 EOS","memo":"ram fee"}
#  signdappplay <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.ramfee","quantity":"0.4990 EOS","memo":"ram fee"}
#  eosio.ramfee <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.ramfee","quantity":"0.4990 EOS","memo":"ram fee"}
#         eosio <= eosio::delegatebw            {"from":"signdappplay","receiver":"dingtet12345","stake_net_quantity":"0.1000 EOS","stake_cpu_quanti...
#   eosio.token <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.stake","quantity":"0.2000 EOS","memo":"stake bandwidth"}
#  signdappplay <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.stake","quantity":"0.2000 EOS","memo":"stake bandwidth"}
#   eosio.stake <= eosio.token::transfer        {"from":"signdappplay","to":"eosio.stake","quantity":"0.2000 EOS","memo":"stake bandwidth"}
warning: transaction executed locally, but may not be confirmed by the network yet

账户向signdappplay账号转一定量的EOS,合约将会自动创建新账户,为CPU和NET各抵押0.1EOS,剩余EOS全部为新账户购买RAM(0.5%手续费)。

参考:

Ubuntu 切换 PHP 版本

PHP5.6 -> 7.0

# 禁用 Apache 中的 PHP5

sudo a2dismod php5.6

# 启用 PHP7

sudo a2enmod php7

# 重启 Apache

sudo systemctl restart apache2.service



# 切换 CLI 

sudo update-alternatives --set php /usr/bin/php7.0

Failed to find shared library for backend ”mysql

编译好sql_db_plugin后启动nodeos

root@iZ2zea5mjpcmz9m17k56daZ:/home/surou/Documents/github/eos/build# nodeos --sql_db-uri=”mysql://db=eos user=root host=127.0.0.1 password='数据库密码' --sql_db-block-start=0  --delete-all-blocks
2018-07-25T12:39:28.628 thread-0   sql_db_plugin.cpp:81          set_program_options  ] set_program_options
2018-07-25T12:39:28.629 thread-0   chain_plugin.cpp:271          plugin_initialize    ] initializing chain plugin
2018-07-25T12:39:28.629 thread-0   chain_plugin.cpp:408          plugin_initialize    ] Deleting state database and blocks
2018-07-25T12:39:28.721 thread-0   chain_plugin.cpp:508          plugin_initialize    ] Starting up fresh blockchain with default genesis state.
2018-07-25T12:39:29.437 thread-0   http_plugin.cpp:344           plugin_initialize    ] configured http to listen on 127.0.0.1:8888
2018-07-25T12:39:29.437 thread-0   net_plugin.cpp:2941           plugin_initialize    ] Initialize net plugin
2018-07-25T12:39:29.437 thread-0   net_plugin.cpp:2966           plugin_initialize    ] host: 0.0.0.0 port: 9876 
2018-07-25T12:39:29.437 thread-0   net_plugin.cpp:3036           plugin_initialize    ] my node_id is e5f1d9687a24d343c57e7ba32913db448147a2e9e7dc1fe12797a69c082e1c9a
2018-07-25T12:39:29.437 thread-0   wallet_plugin.cpp:42          plugin_initialize    ] initializing wallet plugin
2018-07-25T12:39:29.437 thread-0   sql_db_plugin.cpp:96          plugin_initialize    ] initialize
2018-07-25T12:39:29.437 thread-0   sql_db_plugin.cpp:104         plugin_initialize    ] connecting to ”mysql://db=eos
2018-07-25T12:39:29.438 thread-0   main.cpp:141                  main                 ] Failed to find shared library for backend ”mysql

Failed to find shared library for backend ”mysql 错误。
查看EOS代码 eos\programs\nodeos\main.cpp:141

   } catch( const std::runtime_error& e ) {
      if( std::string(e.what()) == "database dirty flag set" ) {
         elog( "database dirty flag set (likely due to unclean shutdown): replay required" );
         return DATABASE_DIRTY;
      } else if( std::string(e.what()) == "database metadata dirty flag set" ) {
         elog( "database metadata dirty flag set (likely due to unclean shutdown): replay required" );
         return DATABASE_DIRTY;
      } else {
         elog( "${e}", ("e",e.what())); // :141
      }
      return OTHER_FAIL;
   } catch( const std::exception& e ) {

应该出在sql_db_plugin中的soci连接中
下载soci源代码

git clone https://github.com/SOCI/soci.git

查看错误出现在

// non-synchronized helper
void do_register_backend(std::string const & name, std::string const & shared_object)
{
    // The rules for backend search are as follows:
    // - if the shared_object is given,
    //   it names the library file and the search paths are not used
    // - otherwise (shared_object not provided or empty):
    //   - file named libsoci_NAME.so.SOVERSION is searched in the list of search paths

    soci_handler_t h = 0;
    if (shared_object.empty() == false)
    {
        h = DLOPEN(shared_object.c_str());
    }
    else
    {
        // try system paths
        h = DLOPEN(LIBNAME(name).c_str());
        if (0 == h)
        {
            // try all search paths
            for (std::size_t i = 0; i != search_paths_.size(); ++i)
            {
                std::string const fullFileName(search_paths_[i] + "/" + LIBNAME(name));
                h = DLOPEN(fullFileName.c_str());
                if (0 != h)
                {
                    // already found
                    break;
                }
             }
         }
    }

    if (0 == h)
    {
        throw soci_error("Failed to find shared library for backend " + name);
    }

发现刚才出现此问题是因为输入的参数符号错误导致,问题停止跟进,以后在遇到类似的再跟进....

Ubuntu 安装MySql 8.0

首先清理干净本地的旧版Mysql

关闭apparmor

sudo /etc/init.d/apparmor stop

关闭mysql

sudo /etc/init.d/mysql stop

删除旧版本

sudo apt-get remove --purge mysql-\*
sudo find  / -name mysql -print //手动删除遗留文件  sudo rm -rf somedir
sudo apt-get remove --purge libmysqlclien\*
sudo apt-get remove apparmor
sudo apt autoremove

添加MySQL Apt存储库

目前已经有了现成可用于安装 MySQL Server、客户端和其它组件的 APT 存储库,我们需要先将 MySQL 存储库添加到 Ubuntu 18.04 的软件包源列表中:

  • 先使用 wget 下载存储库软件包:
    wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb
  • 然后使用以下 dpkg 命令安装下载好的 MySQL 存储库软件包:
    sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

    注意:在软件包安装过程中,系统会提示您选择 MySQL 服务器版本和其他组件,例如群集、共享客户端库或配置要安装 MySQL 的工作台。
    默认 MySQL 服务器版本 mysql-8.0 的源将被自动选中,我们只需最终确定就可以完成发行包的配置和安装。

    在Ubuntu 18.04中安装MySQL 8服务器

    从所有已配置的存储库(包括新添加的 MySQL 8存储库)中下载最新的软件包信息:

    sudo apt update

    然后运行如下命令安装 MySQL 8 社区服务器、客户端和数据库公用文件:

    sudo apt-get install mysql-common mysql-server

    通过安装过程,将会要求为 MySQL 8 服务器的 root 用户输入密码,在输入和再次验证后按回车继续。

    再次输入密码

    此后,需要选择将要使用的默认身份认证插件,选择好之后按回车即可完成程序包配置。

身份认证插件有如下 2 种可供选择:

  • 使用存储密码加密(推荐)
  • 使用传统认证模式(MySQL 5.x 兼容)

问题

如果出现依赖问题

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Errors were encountered while processing:
 mysql-community-server
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

检查下依赖

sudo apt-get install -f