BCSkill (Block chain skill )
区块链中文技术社区

只讨论区块链底层技术
遵守一切相关法律政策!

build fails - Unable to find the requested Boost libraries.

cd  ~/opt
rm -rf boost/
./eos_source_dir/eosio_build.sh

One workaround is to cd into ~/opt and remove the boost library there.
Re-compile using ./eosio_build.sh and it should work.

参考:
https://github.com/EOSIO/eos/issues/3464

EOS合约内解析json

示例代码

//demo.hpp
#pragma once

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
#include "json.hpp"
#include <string>

using json = nlohmann::json;
using eosio::contract;
using eosio::multi_index;
using eosio::print;

class[[eosio::contract]] demo : public contract
{
  public:
    using contract::contract;

    [[eosio::action]] void demoaction();
};
//demo.cpp
#include "demo.hpp"
using json = nlohmann::json;

// ACTION
void demo::demoaction()
{
    json demoInfo = R"(
    {
        "demoInfo": {
            "hello": "world"
        }
    }
    )"_json;
    std::string demoInfoString = demoInfo.dump();
    json demoInfoJson = json::parse(demoInfoString);
    print("It worked\n");
}

EOSIO_DISPATCH(demo, (demoaction))

json.hpp从https://github.com/nlohmann/json/releases 下载并将其放在同一目录中demo.hpp。

参考

https://github.com/EOSIO/eosio.cdt/issues/110

Error compiling LLVM and clang with EXPERIMENTAL WASM support

解决方案:

cd /tmp/llvm-compiler/llvm/build
make -j4 install
rm -rf /tmp/llvm-compiler

最终一般会安装在$HOME/opt/wasm
参考地址:https://github.com/EOSIO/eos/issues/1694

更换Ubuntu镜像,解决EOS编译时,相关依赖下载失败

最近更新EOS代码,由于历史上最伟大的发明qiang,导致编译过程中某些依赖下载失败,so..

ubuntu 18.04

Ubuntu 的软件源配置文件是 /etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用 TUNA 的软件源镜像。

#备份
sudo cp -i /etc/apt/sources.list /etc/apt/sources.list.bak
#编辑
sudo vi /etc/apt/sources.list

将文件内容修改为如下

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

保存后,重新sudo apt-get update后,重新编译

数据来源

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
http://mirrors.ustc.edu.cn/help/ubuntu.html

EOS Encrypt

EOS Encrypt

github: https://github.com/EOS-Nation/eos-encrypt

Allows to encrypt & decypt a message with an EOS key pair using AES shared key encryption mechanism.

Decryption is achieved by combining the receiver's private key and the sender's public key to create the private key necessary to decrypt the message.

This module uses eosjs-ecc to perform the required cryptographic operations.

Install

npm

$ npm install --save eos-encrypt

Usage

import { encrypt, decrypt } from 'eos-encrypt';

const public_key = "EOS6M...DW5CV";
const private_key = "5KQwr...zkvFD3";

const message = "Private Message, shhhh!";
const encrypted = encrypt(private_key, public_key, message);
// => TO DECRYPT: eos-encrypt
// .1167451677...23460624..862584768Q+h1AeLQbjfzZJD1Nsx6kk3U/jSNStwoWstz9uNCadw=

const decrypted = decrypt(private_key, public_key, encrypted);
// => Private Message, shhhh!

API

Table of Contents

encrypt

Encrypt Message

Parameters

  • private_key string EOSIO Private Key
  • public_key string EOSIO Public Key
  • message string Message to Encrypt
  • options object Optional parameters (optional, default {})
    • options.memo string Serialized Memo (optional, default "TO DECRYPT: eos-encrypt\n")
    • options.maxsize number Maximum character message size (optional, default 256)

Examples

const encrypted = encrypt(private_key, public_key, message);

Returns string Encrypted Message

decrypt

Decrypt Message

Parameters

  • private_key string EOSIO Private Key
  • public_key string EOSIO Public Key
  • message string Encrypted Message
  • options object Optional parameters (optional, default {})
    • options.memo string Serialized Memo (optional, default "TO DECRYPT: eos-encrypt\n")

Examples

const decrypted = decrypt(private_key, public_key, message);

Returns string Decrypted Message

setMemo

Set Default Memo

Parameters

Examples

setMemo("TO DECRYPT: my-dapp\n");

Returns void