Ethereum 源码分析之 accounts
一、Account
// Account represents an Ethereum account located at a specific location defined
// by the optional URL field.
// Account,代表一个位于由可选的URL字段定义的具体位置的以太坊账户
// Address,地址是20个字节,由私钥衍生。。URL,可选字段,后端的资源位置
type Account struct {
Address common.Address `json:"address"` // Ethereum account address derived from the key
URL URL `json:"url"` // Optional resource locator within a backend
}
二、Wallet
type Wallet interface {
// URL retrieves the canonical path under which this wallet is reachable. It is
// user by upper layers to define a sorting order over all wallets from multiple
// backends.
// URL 用来获取这个钱包可以访问的规范路径。被上层使用,为所有来自于各种backend的钱包定义一个排序
URL() URL // Status returns a textual status to aid the user in the current state of the
// wallet. It also returns an error indicating any failure the wallet might have
// encountered.
// Status 返回钱包的当前状态的文本来帮助使用者。同时返回一个错误来指示钱包可能会遇到的任何错误
Status() (string, error) // Open initializes access to a wallet instance. It is not meant to unlock or
// decrypt account keys, rather simply to establish a connection to hardware
// wallets and/or to access derivation seeds.
//
// The passphrase parameter may or may not be used by the implementation of a
// particular wallet instance. The reason there is no passwordless open method
// is to strive towards a uniform wallet handling, oblivious to the different
// backend providers.
//
// Please note, if you open a wallet, you must close it to release any allocated
// resources (especially important when working with hardware wallets).
// Open 初始化对钱包实例的访问。这个方法并不意味着解锁或者解密账户秘钥,而是简单地建立与硬件钱包的连接和/或访问衍生种子。
// 请注意,如果你open了一个钱包,你必须close它。不然有些资源可能没有释放。特别是使用硬件钱包的时候需要特别注意。
Open(passphrase string) error // Close releases any resources held by an open wallet instance.
// Close 释放一个打开的钱包实例的占用的任何资源。
Close() error // Accounts retrieves the list of signing accounts the wallet is currently aware
// of. For hierarchical deterministic wallets, the list will not be exhaustive,
// rather only contain the accounts explicitly pinned during account derivation.
// Accounts 用来获取钱包正发现的账户列表。对于分层次的钱包,这个列表不会详尽的列出所有的账号,而是只包含在帐户派生期间明确固定的帐户。
Accounts() []Account // Contains returns whether an account is part of this particular wallet or not.
// Contains 返回一个账号是否属于本钱包。
Contains(account Account) bool // Derive attempts to explicitly derive a hierarchical deterministic account at
// the specified derivation path. If requested, the derived account will be added
// to the wallet's tracked account list.
// Derive 尝试在指定的派生路径上显式派生出分层确定性帐户。如果pin为true,派生帐户将被添加到钱包的跟踪帐户列表中。
Derive(path DerivationPath, pin bool) (Account, error) // SelfDerive sets a base account derivation path from which the wallet attempts
// to discover non zero accounts and automatically add them to list of tracked
// accounts.
//
// Note, self derivaton will increment the last component of the specified path
// opposed to decending into a child path to allow discovering accounts starting
// from non zero components.
//
// You can disable automatic account discovery by calling SelfDerive with a nil
// chain state reader.
// SelfDerive 设置一个基本帐户导出路径,从中钱包尝试发现非零帐户,并自动将其添加到跟踪帐户列表中。
// 注意,SelfDerive将递增指定路径的最后一个组件,而不是下降到子路径,以允许从非零组件开始发现帐户。
// 你可以通过传递一个nil的ChainStateReader来禁用自动账号发现。
SelfDerive(base DerivationPath, chain ethereum.ChainStateReader) // SignHash requests the wallet to sign the given hash.
//
// It looks up the account specified either solely via its address contained within,
// or optionally with the aid of any location metadata from the embedded URL field.
//
// If the wallet requires additional authentication to sign the request (e.g.
// a password to decrypt the account, or a PIN code o verify the transaction),
// an AuthNeededError instance will be returned, containing infos for the user
// about which fields or actions are needed. The user may retry by providing
// the needed details via SignHashWithPassphrase, or by other means (e.g. unlock
// the account in a keystore).
// SignHash 请求钱包来给传入的hash进行签名。
// 它可以通过其中包含的地址(或可选地借助嵌入式URL字段中的任何位置元数据)来查找指定的帐户。
// 如果钱包需要额外的验证才能签名(比如说需要密码来解锁账号,或者是需要一个PIN代码来验证交易),
// 会返回一个AuthNeededError的错误,里面包含了用户的信息,以及哪些字段或者操作需要提供。
// 用户可以通过SignHashWithPassphrase来签名或者通过其他手段(在keystore里面解锁账号)
SignHash(account Account, hash []byte) ([]byte, error) // SignTx requests the wallet to sign the given transaction.
//
// It looks up the account specified either solely via its address contained within,
// or optionally with the aid of any location metadata from the embedded URL field.
//
// If the wallet requires additional authentication to sign the request (e.g.
// a password to decrypt the account, or a PIN code to verify the transaction),
// an AuthNeededError instance will be returned, containing infos for the user
// about which fields or actions are needed. The user may retry by providing
// the needed details via SignTxWithPassphrase, or by other means (e.g. unlock
// the account in a keystore).
// SignTx 请求钱包对指定的交易进行签名。
SignTx(account Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) // SignHashWithPassphrase requests the wallet to sign the given hash with the
// given passphrase as extra authentication information.
//
// It looks up the account specified either solely via its address contained within,
// or optionally with the aid of any location metadata from the embedded URL field.
// SignHashWithPassphrase 请求钱包使用给定的passphrase来作为额外的认证信息去签名给定的hash
SignHashWithPassphrase(account Account, passphrase string, hash []byte) ([]byte, error) // SignTxWithPassphrase requests the wallet to sign the given transaction, with the
// given passphrase as extra authentication information.
//
// It looks up the account specified either solely via its address contained within,
// or optionally with the aid of any location metadata from the embedded URL field.
// SignHashWithPassphrase 请求钱包使用给定的passphrase来作为额外的认证信息去签名给定的transaction
SignTxWithPassphrase(account Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
}
三、Backend
// Backend is a "wallet provider" that may contain a batch of accounts they can
// sign transactions with and upon request, do so.
// Backend 是一个钱包提供器,包含一批账号。他们可以根据请求签署交易
type Backend interface {
// Wallets retrieves the list of wallets the backend is currently aware of.
//
// The returned wallets are not opened by default. For software HD wallets this
// means that no base seeds are decrypted, and for hardware wallets that no actual
// connection is established.
//
// The resulting wallet list will be sorted alphabetically based on its internal
// URL assigned by the backend. Since wallets (especially hardware) may come and
// go, the same wallet might appear at a different positions in the list during
// subsequent retrievals.
// 检索backend当前知道的一批钱包,返回的钱包默认是关闭的
// 所产生的钱包列表将根据后端分配的内部URL按字母顺序排序。由于钱包(特别是硬件钱包)可能会打开和关闭,
// 所以在随后的检索过程中,相同的钱包可能会出现在列表中的不同位置。
Wallets() []Wallet // Subscribe creates an async subscription to receive notifications when the
// backend detects the arrival or departure of a wallet.
// 创建异步订阅,以便在后端检测到钱包的到达或离开时接收通知。
Subscribe(sink chan<- WalletEvent) event.Subscription
}
Ethereum 源码分析之 accounts的更多相关文章
- [ethereum源码分析](3) ethereum初始化指令
前言 在上一章介绍了关于区块链的一些基础知识,这一章会分析指令 geth --datadir dev/data/02 init private-geth/genesis.json 的源码,若你的eth ...
- go ethereum源码分析 PartIV Transaction相关
核心数据结构: core.types.transaction.go type Transaction struct { data txdata // caches hash atomic.Value ...
- [ethereum源码分析](5) 创建新账号
前言 在上一章我们介绍了 ethereum运行开启console 的过程,那么在这一章我们将会介绍如何在以太坊中创建一个新的账号.以下的理解可能存在错误,如果各位大虾发现错误,还望指正. 指令分析 指 ...
- [ethereum源码分析](4) ethereum运行开启console
前言 在上一章我们介绍了 ethereum初始化指令 ,包括了系统是如何调用指令和指令的执行.在本章节我们将会介绍 geth --datadir dev/data/ --networkid cons ...
- Ethereum 源码分析之框架
accounts 实现了一个高等级的以太坊账户管理 bmt 二进制的默克尔树的实现 build 主要是编译和构建的一些脚本和配置 cmd ...
- [ethereum源码分析](2) ethereum基础知识
前言 上一章我们介绍了如何搭建ethereum的debug环境.为了更深入的了解ethereum,我们需要了解一些ethereum的相关的知识,本章我们将介绍这些知识. ethereum相关知识 在学 ...
- [ethereum源码分析](1) dubug环境搭建
前言 因为最近云小哥哥换了一份工作,新公司比较忙,所以一直没有更新新的博客.云小哥哥新的公司是做区块链的,最近在学习区块链相关的东西(也算是乘坐上了区块链这艘大船).本博客是记录我搭建ethereum ...
- Android7.0 Phone应用源码分析(一) phone拨号流程分析
1.1 dialer拨号 拨号盘点击拨号DialpadFragment的onClick方法会被调用 public void onClick(View view) { int resId = view. ...
- 【精】EOS智能合约:system系统合约源码分析
系统合约在链启动阶段就会被部署,是因为系统合约赋予了EOS链资源.命名拍卖.基础数据准备.生产者信息.投票等能力.本篇文章将会从源码角度详细研究system合约. 关键字:EOS,eosio.syst ...
随机推荐
- Hdu2102 A计划 2017-01-18 14:40 60人阅读 评论(0) 收藏
A计划 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- android周期性任务
一般任务调度机制的实现方式主要有: Thread sleep.Timer.ScheduledExecutor.Handler和其他第三方开源库.android的AlarmManager 1. Time ...
- windows下用C++获取本机IP地址
BSTR CamUtilsCtrl::GET_TERM_IP(void){ AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strResult ...
- DagScheduler 和 TaskScheduler
DagScheduler 和 TaskScheduler 的任务交接 spark 调度器分为两个部分, 一个是 DagScheduler, 一个是 TaskScheduler, DagSchedule ...
- sun.jersey使用Jackson转换数据
差点被com.sun.jersey自身的json转换吓死,遇到List等类型,会把这些也转换为json对象,而不是jsonarray. 被园里的同行拯救了,在web.xml中配置一下就ok. < ...
- linux系统编程之文件与IO(三):利用lseek()创建空洞文件
一.lseek()系统调用 功能说明: 通过指定相对于开始位置.当前位置或末尾位置的字节数来重定位 curp,这取决于 lseek() 函数中指定的位置 函数原型: #include <sys/ ...
- jquery chosen 插件多选初始化
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- C#在dataGridView中遍历,寻找相同的数据并定位
1. C#在dataGridView中遍历,寻找相同的数据并定位 [c-sharp] view plain copy int row = dataGridView1.Rows.Count;// ...
- NetCore入门篇:(十二)在IIS中部署Net Core程序
一.简介 微软已经为net在iis中的部署提供了良好的支持,在IIS中部署NetCore是一件很容易的事. 二.在IIS中部署Net Core程序 1.微软官方文档有详细说明.进入 2.如果你已经熟悉 ...
- .net core2.0 codefirst 创建数据库的问题!
appsettings.json和Startup.cs就不记录了,网上很多!! 1.必须在有DbContext类的项目里添加这3个NuGet引用 Microsoft.EntityFrameworkCo ...