您正在查看: Surou 发布的文章

EOS离线下载块历史数据地址

The archive consists of state, blocks, and state-history archives, plus a copy of a portable snapshot made by EOS Sweden on the day prior to the snapshop. This should help if your environment is different. The archives are made with eosio_1.8.1-1-ubuntu-18.04_amd64.deb Debian package.

https://snapshots.eosamsterdam.net/eos/

区块链私钥管理开源库- a blockchain private key management library

https://github.com/consenlabs/token-core-android
https://github.com/consenlabs/token-core-ios

String prvKey = WalletManager.exportPrivateKey(ethereumWallet.getId(), SampleKey.PASSWORD);
System.out.println(String.format("PrivateKey: %s", prvKey));
String mnemonic = WalletManager.exportMnemonic(ethereumWallet.getId(), SampleKey.PASSWORD).getMnemonic();
System.out.println(String.format("Mnemonic: %s", mnemonic));
String json = WalletManager.exportKeystore(ethereumWallet.getId(), SampleKey.PASSWORD);
System.out.println(String.format("Keystore: %s", json));

// output:
// PrivateKey: f653be3f639f45ea1ed3eb152829b6d881ce62257aa873891e06fa9569a8d9aa
// Mnemonic: tide inmate cloud around wise bargain celery cement jungle melody galaxy grocery
// Keystore: {"id":"c7575eba-3ae3-4cc3-86ba-2eb9c6839cad","version":3,"crypto":{"ciphertext":"7083ba3dd5470ba4be4237604625e05fa6b668954d270beb848365cbf6933ec5","mac":"f4f9ea8d42ff348b11fc146c396da446cc975309b3538e08a58c0b218bddd15d","cipher":"aes-128-ctr","cipherparams":{"iv":"db3f523faf4da4f1c6edcd7bc1386879"},"kdf":"pbkdf2","kdfparams":{"dklen":32,"c":10240,"prf":"hmac-sha256","salt":"0ce830e9f888dfe33c31e6cfc444d6f588161c9d4128d4066ee5dfdcbc5d0079"}},"address":"4a1c2072ac67b616e5c578fd9e2a4d30e0158471"}

EOS合约内unpack data

void myaction() {

   struct token_transfer {
      name from;
      name to;
      asset quantity;
      string memo;
   };

   // transaction is inside "prop" object (that we get from a eosio.msig table)
   eosio::multisig::proposals proptable( "eosio.msig"_n, proposer.value );
   auto& prop = proptable.get( proposal_name.value, "proposal not found" );

   // get the first action in the transaction, remember transactions can have multiple actions
   eosio::action my_action = eosio::unpack<eosio::transaction>( prop.packed_transaction ).actions.front();

   // get the data out of the action
   token_transfer my_action_data = my_action.data_as<token_transfer>();

   const name from      = my_action_data.from;
   const name to        = my_action_data.to;
   const asset quantity = my_action_data.quantity;
   const string memo    = my_action_data.memo;
}

参考

https://eosio.stackexchange.com/questions/4142/how-to-get-data-from-a-packed-transaction

关于传统项目转区块链项目

关于传统项目转区块链项目

引入区块链的优势

对于项目方

  1. 想把目前传统项目蹭区块链的热度,传统项目“转型”
  2. 想以此发token,
  3. 增加用户粘性

对于用户

  1. 传统的“数据库积分”可以通过区块链的资金体系流通,并“绕过限制”到交易所变现
  2. 解决信任,计算token的逻辑以及相关源数据去中心化

项目转型的实现

分为资产去中心化以及数据去中心化

资产去中心化

其实主要是怎么实现Token产出,可以先从传统互联网中心化应用的玩法设计,类似于需要数据才能计算出来奖励。

对于区块链去中心化设计,可以分成三个等级

  1. 完全去中心化,服务方与用户分别提供相关数据上链,通过链上智能合约,根据双方提供的源数据,计算奖励。
  2. 相对去中心化,服务方提供相关可以公开的数据上链,通过链上智能合约,根据提供的源数据,计算奖励。
  3. 资产去中心化,服务方根据相关数据,中心化计算相关的奖励,然后将奖励数据推到链上智能合约。

相关计算结果以及相关日志推送上链,用户可从区块浏览器等查看相关日志,根据相关数据验证资产产生的准备性。

数据去中心化

对于数据,分为可公开以及隐私数据

可公开的数据

如果数据量较小的话,可以直接写到智能合约内。对于数据量较大时,可以中心化提供源数据展示,并将数据校验指纹上链,并提供数据校验的工具给用户方,用户可随时进行比对校验。

隐私数据

如果数据量小的话,可以将数据本地加密推送上链,并通过共享加密策略指定相关用户可以解密查看。对于数据量较大的数据,数据验证指纹上链,通过中心化授权系统,指定相关用户可授权访问中心化源数据。

项目策略选定

对于目前传统稍大型项目,一些相关数据较多,且不易公开,并且用户关心点并不是必须完全去中心化。可以优先选定策略为“相对去中心化”,如果只关心资产交易的话,可以选择“资产去中心化”。对于数据的去中心化可以选择大数据量方案,可灵活控制访问授权。

项目实现所需准备

根据具体产品逻辑再定。

Hyperion History API 详细部署

安装java

sudo apt-get install openjdk-8-jdk

安装elasticsearch

下载

https://www.elastic.co/cn/downloads/elasticsearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.0-amd64.deb

安装

sudo dpkg -i elasticsearch-7.4.0-amd64.deb

程序位置 /usr/share/elasticsearch/
配置文件 /etc/elasticsearch/elasticsearch.yml

启动es

service elasticsearch start

测试

curl http://localhost:9200/

返回

{
  "name" : "fscshare",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "jwNw7I-sSvevCWg9p-ibsg",
  "version" : {
    "number" : "7.4.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "22e1767283e61a198cb4db791ea66e3f11ab9910",
    "build_date" : "2019-09-27T08:36:48.569419Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

及安装正确。

停止es (按需要)

cat /var/run/elasticsearch/elasticsearch.pid  && echo # 获得pid
sudo kill -SIGTERM 81937

Kibana (按需要)

为了能够可视化es中的数据并操作es

下载

https://www.elastic.co/cn/downloads/kibana

wget https://artifacts.elastic.co/downloads/kibana/kibana-7.4.0-amd64.deb

安装

sudo dpkg -i kibana-7.4.0-amd64.deb

位置 /usr/share/kibana/
启动 /usr/share/kibana/bin/kibana
访问 http://localhost:5601

安装RabbitMQ

sudo apt-get update -y
sudo apt-get install -y rabbitmq-server
sudo service rabbitmq-server start
辅助方法
# stop the local node
sudo service rabbitmq-server stop
# start it back
sudo service rabbitmq-server start
# check on service status as observed by service manager

sudo service rabbitmq-server status
RabbitMQ 添加用户

测试配置如下

sudo rabbitmq-plugins enable rabbitmq_management
sudo rabbitmqctl add_vhost /hyperion
sudo rabbitmqctl add_user my_user my_password
sudo rabbitmqctl set_user_tags my_user administrator
sudo rabbitmqctl set_permissions -p /hyperion my_user ".*" ".*" ".*"

安装Redis

sudo apt update
sudo apt install redis-server

辅助方法

sudo service redis restart
sudo systemctl status redis

安装 Node.js v12.x

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

安装PM2

sudo npm install pm2@latest -g

安装Nodeos 1.8.4 w/ 并开启 state_history_plugin and chain_api_plugin

wget https://github.com/eosio/eos/releases/download/v1.8.4/eosio_1.8.4-1-ubuntu-18.04_amd64.deb
sudo apt install ./eosio_1.8.4-1-ubuntu-18.04_amd64.deb
nodeos --config-dir ~/eosio/chain/config  --genesis-json ~/eosio/chain/config/genesis.json --data-dir ~/eosio/chain/data -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::state_history_plugin --disable-replay-opts  --chain-state-history --trace-history --delete-all-blocks

Clone & Install Hyperion-History-API

git clone https://github.com/bcskill/Hyperion-History-API.git
cd Hyperion-History-API
npm install

修改配置

cp example-ecosystem.config.js ecosystem.config.js

vi ecosystem.config.js

module.exports = {
    apps: [
        {
            name: "Indexer",
            script: "./launcher.js",
            node_args: ["--max-old-space-size=8192"],
            autorestart: false,
            kill_timeout: 3600,
            env: {
                AMQP_HOST: '127.0.0.1:5672',
                AMQP_USER: 'my_user',
                AMQP_PASS: 'my_password',
                REDIS_HOST: '127.0.0.1',
                REDIS_PORT: '6379',
                ES_HOST: '127.0.0.1:9200',
                NODEOS_HTTP: 'http://127.0.0.1:8888',
                NODEOS_WS: 'ws://127.0.0.1:8080',
                START_ON: 0,
                STOP_ON: 0,
                REWRITE: 'false',
                BATCH_SIZE: 5000,
                LIVE_READER: 'false',
                LIVE_ONLY: 'false',
                FETCH_BLOCK: 'false',
                FETCH_TRACES: 'false',
                CHAIN: 'eos',
                CREATE_INDICES: 'v1',
                PREVIEW: 'false',
                DISABLE_READING: 'false',
                READERS: 1,
                DESERIALIZERS: 1,
                DS_MULT: 1,
                ES_INDEXERS_PER_QUEUE: 1,
                ES_ACT_QUEUES: 1,
                READ_PREFETCH: 50,
                BLOCK_PREFETCH: 100,
                INDEX_PREFETCH: 500,
                ENABLE_INDEXING: 'true',
                PROC_DELTAS: 'true',
                INDEX_DELTAS: 'true',
                INDEX_ALL_DELTAS: 'false',
                ABI_CACHE_MODE: 'false',
                ACCOUNT_STATE: 'false',
                VOTERS_STATE: 'false',
                USERRES_STATE: 'false',
                DELBAND_STATE: 'false',
                REPAIR_MODE: 'false',
                DEBUG: 'false'
            }
        },
        {
            name: 'API',
            script: "./api/api-loader.js",
            exec_mode: 'cluster',
            merge_logs: true,
            instances: 4,
            autorestart: true,
            exp_backoff_restart_delay: 100,
            watch: ["api"],
            env: {
                AMQP_HOST: "localhost:5672",
                AMQP_USER: "my_user",
                AMQP_PASS: "my_password",
                REDIS_HOST: '127.0.0.1',
                REDIS_PORT: '6379',
                SERVER_PORT: '7000',
                SERVER_NAME: 'example.com',
                SERVER_ADDR: '127.0.0.1',
                NODEOS_HTTP: 'http://127.0.0.1:8888',
                ES_HOST: '127.0.0.1:9200',
                CHAIN: 'eos'
            }
        }
    ]
};

启动

Starting

pm2 start --only Indexer --update-env
pm2 logs Indexer

Stopping

// Stop reading and wait for queues to flush

pm2 trigger Indexer stop
Force stop
pm2 stop Indexer

Starting the API node

pm2 start --only API --update-env
pm2 logs API

测试

curl -X GET "http://127.0.0.1:7000/health" -H "accept: */*"

返回

{
    "health": [{
        "service": "RabbitMq",
        "status": "OK",
        "time": 1571055356654
    }, {
        "service": "Redis",
        "status": "OK",
        "time": 1571055356655
    }, {
        "service": "Elasticsearch",
        "status": "OK",
        "time": 1571055356656
    }]
}

参考

https://github.com/eosrio/Hyperion-History-API
https://www.jianshu.com/p/7200cd17d8cb
https://www.rabbitmq.com/install-debian.html
https://wangxin1248.github.io/linux/2018/07/ubuntu18.04-install-redis.html
https://pm2.keymetrics.io/docs/usage/quick-start/
https://github.com/EOSIO/eos/issues/6334