hash256

Stanford Javascript Crypto Library
这个库能和 golang 的 sha256算出来的一致。
sha256(test) = 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08

sjcl.hash.sha256.hash actually supports only ASCII characters.
这个计算下面的 binary 输入就会有问题。因为他只支持string hash 这个库不要用了。

https://github.com/brix/crypto-js

一个在线的 java 库实现的 hash 工具
http://www.fileformat.info/tool/hash.htm

hash 输入分为三种:string, binary, file
使用 string hash 计算:
02b73db82dccc08f1bc6d2bd712a197553fc4b284a032931e138c77f63932a7fb9
SHA-256 bc6a7c8fd8bcadffd398bfbf9612b9c9f00baf3456da916f7e54f5499399e893

使用 binary hash 计算
02b73db82dccc08f1bc6d2bd712a197553fc4b284a032931e138c77f63932a7fb9
SHA-256 319ebb68e7070b821436e8401f14113379232c96a996b0de0fd10ac7fd3553a9

加解密操作是用的binary hash计算方式。

需要把 string 类型转换为 hex 然后在计算 hash 值才行

#include <iostream>
#include <tuple>
#include <functional>

std::tuple<int, int> f() // 此函数返回多值
{
int x = 5;
return std::make_tuple(x, 7); // return {x,7}; 于 C++17
}

int main()
{
// 异类 tuple 构造
int n = 1;
auto t = std::make_tuple(10, "Test", 3.14, std::ref(n), n);
n = 7;
std::cout << "The value of t is " << "("
<< std::get<0>(t) << ", " << std::get<1>(t) << ", "
<< std::get<2>(t) << ", " << std::get<3>(t) << ", "
<< std::get<4>(t) << ")\n";

// 返回多值的函数
int a, b;
std::tie(a, b) = f();
auto [a, b] = f();

std::cout << a << " " << b << "\n";

auto t = std::make_tuple(1, "Foo", 3.14);
// index-based access
std::cout << "(" << std::get<0>(t) << ", " << std::get<1>(t)
<< ", " << std::get<2>(t) << ")\n";
}

office site
https://swagger.io/solutions/api-design/
https://swagger.io/tools/

待学习文档
https://www.ibm.com/developerworks/cn/web/wa-use-swagger-to-document-and-define-restful-apis/index.html

Swagger 能成为最受欢迎的REST APIs文档生成工具之一,有以下几个原因:

  • 可以生成一个具有互动性的API控制台,开发者可以用来快速学习和尝试API。
  • 可以生成客户端SDK代码用于各种不同的平台上的实现。
  • 文件可以在许多不同的平台上从代码注释中自动生成。
  • 有一个强大的社区,里面有许多强悍的贡献者。

文档提供了一个方法,使我们可以用指定的 JSON 或者 YAML 摘要来描述你的 API,包括了比如 names、order 等 API 信息。

你可以通过一个文本编辑器来编辑 Swagger 文件,或者你也可以从你的代码注释中自动生成。各种工具都可以使用 Swagger 文件来生成互动的 API 文档。

如果你后台开发,提供restful接口给前端。建议你使用swagger-ui提供restful的接口文档描述。
如果你是接口设计者,建议你使用Swagger Editor设计。
如果你是接口调用方,想快速生成接口调用代码,很简单,你只需要使用Swagger Editor生存client代码就行了,十分方便。

C11标准中的新语法,用于让程序员在代码中提供额外信息

void f [[ noreturn ]] () // f() 永不返回
{
throw "error"; // 虽然不得返回,但可以抛出异常
}

struct foo* f [[carries_dependency]] (int i); // 编译优化指示
int* g(int* x, int* y [[carries_dependency]]);

属性被放置在两个双重中括号“[[…]]”之间。目前,noreturn和carries_dependency是C++11标准中仅有的两个通用属性。

  • nodeos (node + eos = nodeos)
    the core EOSIO node daemon that can be configured with plugins to run a node. Example uses are block production, dedicated API endpoints, and local development.
  • cleos (cli + eos = cleos)
    command line interface to interact with the blockchain and to manage wallets
  • keosd (key + eos = keosd)
    component that securely stores EOSIO keys in wallets.
dedd9507.png

创建好EOS账户后,务必先要进行系统资源配置
EOS 共有三大资源:CPU、NET(网络带宽)和 RAM(内存)
CPU 和 NET 需要临时抵押 EOS 获取,类似于交押金,不用了可以赎回 EOS。
RAM 只能用 EOS 直接购买/卖出,因为它是存储状态的,是长期占用的。简单来说,就是根据链上的数据产生的状态是存储在 RAM 中的,如一个账号的信息,包括余额的当前状态都是存储在 RAM 中的,因此需要购买 RAM 来长期存储数据。
基础配置推荐:CPU:0.5EOS,RAM:0.1EOS,NET:0.1EOS,该配置能满足正常的交易需求了。

注意:当账号没有资源时是不允许自己给自己购买RAM或者抵押获得NET和CPU,因为这本身就是一次交易,需要消耗资源,第一次的操作需要通过其他账号进行。

区块生产者可以

RAM

用来在区块链上保存数据的资源,需要用 EOS 购买,就像 EOS 一样,RAM 价格会跟据需求和供给波动的,通过 Bancor Relay算法自动调节
创建账户需要消耗RAM。RAM是EOS主网中的内存,用于存储用户在EOS中使用频率高的数据(账户余额、合约状态等)。
当存储账号状态的空间不足,即RAM不足时,转账或部署合约等相关操作就无法执行。

CPU

当执行交易和执行 action 的时候会需要 cpu 带宽,运行时间越长,需要的 cpu 带宽就越多。
通过抵押 EOS 来获取 CPU 资源,并且可以赎回,但是有三天的等待期。
还可以出租 CPU 资源,

NET

当执行交易和执行 action 的时候会需要 net 带宽
通过抵押 EOS 来获取 NET 资源

质押的好处

  1. 防止攻击倒币,因为有三天的赎回期
  2. 通过质押,可以不用支付交易费用
  3. 保障 EOS 的存在

GitHub

EOS源码调试及跟踪(下)
http://bitbee.io/d/5b8f601014f8bf4896d27b91

Mac

clion cmake option:
-DWASM_ROOT=~/opt/wasm

MacOS Darwin 10.12 and higher (MacOS 10.13.x recommended)

rm -rf /path/to/eos
git clone https://github.com/EOSIO/eos.git --recursive
git submodule update --init --recursive
./eosio_build.sh
// Mac OS X Brew Install
brew tap eosio/eosio
brew install eosio

// response
/usr/local/Cellar/eosio/1.4.4: 14 files, 61.9MB

// Mac OS X Brew Uninstall
brew remove eosio

centos

wget https://github.com/EOSIO/eos/releases/download/v1.5.0/eosio-1.5.0-1.el7.x86_64.rpm

sudo yum install ./eosio-1.4.4-1.el7.x86_64.rpm
阅读全文 »

std::set<int> myset;
myset.insert(100);
myset.insert(200);
myset.clear();

if (myset.count(i) != 0)
std::cout << " is an element of myset.\n";
else
std::cout << " is not an element of myset.\n";

{ // cbegin/cend(c++11): Returns a const_iterator pointing to the first element in the container/
// Returns a const_iterator pointing to the past-the-end element in the container
std::set<int> myset = { 50, 20, 60, 10, 25 };

std::cout << "myset contains:";
for (auto it = myset.cbegin(); it != myset.cend(); ++it)
std::cout << ' ' << *it;

std::cout << '\n';
}

{ // crbegin/crend(c++11):Return const_reverse_iterator to reverse beginning/
// Return const_reverse_iterator to reverse end
std::set<int> myset = { 50, 20, 60, 10, 25 };

std::cout << "myset backwards:";
for (auto rit = myset.crbegin(); rit != myset.crend(); ++rit)
std::cout << ' ' << *rit;

std::cout << '\n';
}


Posted on February 23, 2017

The 2-Way peg is often said to be a method to transfer BTC into RBTC and vice-versa. In practice, when BTC are exchanged for RBTC, no currency is “transferred” between blockchains. There is no single transaction that does the job. This is because Bitcoin cannot verify the authenticity of balances on another blockchain. When a user intends to convert BTC to RBTC, some BTC are locked in Bitcoin and the same amount of RBTC is unlocked in RSK. When RBTC needs to be converted back into BTC, the RBTC get locked again in RSK and the same amount of BTC are unlocked in the Bitcoin blockchain. A security protocol ensures that the same Bitcoins cannot be unlocked on both blockchains at the same time.

量子纠缠

就是两个粒子相互关联,相互影响。比如A粒子状态是上,B粒子状态是下。如果A粒子变成下了,B粒子就会从下变成上。

叠加态

一个粒子可以同时表示多种状态,比如即是0,又是1,

量子纠缠怎么产生的

简单来说就是,本来有个微观粒子,通过某种手段一分为二了,于是就是产生两个相反方向运动的粒子。

听得最多的微观粒子是电子和光子,也就是电子纠缠和光子纠缠了。
光子:路径,偏振,角动量

实验室中最常见制备量子纠缠的方式就是衰变零自旋中性π介子,
原本中性π介子衰变后会变成一个(带负电)电子和一个正电子,电子和正电子互为反物质!
它们会朝着相反的方向运动,
如果不去测量它们,那么这个电子和正电子的共同会形成零自旋的纠缠状态。
如果观测其中一个粒子,比如电子,那么它们之间的纠缠态就会确定,导致电子和正电子都有了相反状态的自旋。
如果观测电子的自旋为下,那么与之纠缠的正电子自旋必为上。就产生了量子纠缠