5.6 以太坊原始碼詳解6

尹成發表於2018-11-09

1、概念

  • 以太坊地址:代表一個賬戶
  • 形式:0x97FBAb0a865fb81A8A22dA3798424398387413D8
  • 特點:全網唯一

2、如何生成全網唯一的地址

1)、 建立賬戶

// accountCreate creates a new account into the keystore defined by the CLI flags.
func accountCreate(ctx *cli.Context) error {
    cfg := gethConfig{Node: defaultNodeConfig()}//獲取配置
    // Load config file. 載入配置檔案
    if file := ctx.GlobalString(configFileFlag.Name); file != "" {
        if err := loadConfig(file, &cfg); err != nil {
            utils.Fatalf("%v", err)
        }
    }
    utils.SetNodeConfig(ctx, &cfg.Node)
    scryptN, scryptP, keydir, err := cfg.Node.AccountConfig()
    if err != nil {
        utils.Fatalf("Failed to read configuration: %v", err)
    }
// 獲取密碼
    password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
// 儲存到私鑰檔案中
    address, err := keystore.StoreKey(keydir, password, scryptN, scryptP)
    if err != nil {
        utils.Fatalf("Failed to create account: %v", err)
    }
    fmt.Printf("Address: {%x}\n", address) //列印地址
    return nil
}

 

相關文章