比原项目仓库:

Github地址:https://github.com/Bytom/bytom

Gitee地址:https://gitee.com/BytomBlockchain/bytom

Bytom-Mobile-Wallet-SDK 是从bytom源码中抽离出的钱包层代码,并且对钱包层代码进行了改造。使用gomobile可以将代码 编译成Android和iOS平台可用的SDK,使用编译后的Android和iOS钱包SDK可以在移动端实现创建bytom密钥、账户、地址和交易签名功能。

Bytom-Mobile-Wallet-SDK源码简介

SDK源码放在项目的sdk文件夹中,android和ios文件夹是使用SDK的demo项目,bind.go 中首字母大写可以外部调用的函数会作为提供给Android和iOS调用的API。bytom创建的密钥对会存储在磁盘单独的文件中,而且对私钥进行了加密,账户地址数据是存储在go实现的leveldb中,所以Android和iOS平台也需要提供数据存储的路径。

func InitWallet(storagePath string) {
hsm := pseudohsm.New(storagePath)
walletDB := db.NewDB("wallet", "leveldb", storagePath)
accounts := account.NewManager(walletDB)
assets := asset.NewRegistry(walletDB)
wallet := aWallet.NewWallet(walletDB, accounts, assets, hsm)
api = aApi.API{Wallet: wallet}
}

Android和iOS平台调用其他钱包API的之前需要先调用InitWallet这个API,参数是磁盘上的绝对路径,InitWallet会对整个钱包进行一个初始化, 其中最重要是初始化leveldb的存储。其他的CreateKey、CreateAccount、CreateAccountReceiver是创建密钥、账户、地址等API,RestoreWallet API能够对钱包所有账户地址资产进行备份导出json格式的数据。

Bytom-Mobile-Wallet-SDK的编译

SDK代码的编译首先需要正确的安装golang和gomobile,golang需要1.7以上版本。

Android平台需要安装JDK、Android SDK、Android NDK,并且需要将Android SDK的platform-tools、ndk-bundle 添加到PATH系统环境变量中。iOS平台编译环境配置相对比较简单只需要安装Xcode就可以了。

Clone项目到本地$GOPATH/src下:

 git clone https://github.com/Bytom-Community/Bytom-Mobile-Wallet-SDK $GOPATH/src/github.com/bytom-community/mobile

Android

gomobile init -ndk ~/path/to/your/ndk
cd $GOPATH/src/github.com/bytom-community/mobile
gomobile bind -target=android github.com/bytom-community/mobile/sdk/

如果需要减小SDK的体积给gomobile bind指令加上-ldflags=-s参数:

gomobile bind -target=android -ldflags=-s github.com/bytom-community/mobile/sdk/

执行指令后会在mobile文件夹生成wallet.aar和wallet-sources.jar文件。

iOS

cd $GOPATH/src/github.com/bytom-community/mobile
gomobile bind -target=ios github.com/bytom-community/mobile/sdk/

如果需要减小SDK的体积给gomobile bind指令加上-ldflags=-w参数:

$ gomobile bind -target=ios -ldflags=-w github.com/bytom-community/mobile/sdk/

执行指令后会在mobile文件夹生成wallet.framework文件。

由于gomobile现在没有支持bitcode,所以生成的iOS SDK也不支持bitcode。

Bytom-Mobile-Wallet-SDK的使用

Android

拷贝wallet.aar和wallet-sources.ja到Android项目的app的libs文件夹下,并在app module中的build.gradle文件中添加:

android {
repositories {
flatDir { dirs 'libs' }
}
} dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation(name: 'wallet', ext: 'aar')
}

sync project后可以在Android项目中对SDK的API进行调用:

package io.bytom.community;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView; import wallet.Wallet; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView keyTextView = (TextView) findViewById(R.id.key_textview); String storagePath = getFilesDir().toString();
Log.d("storagePath", storagePath); Wallet.initWallet(storagePath);
String keyResult = Wallet.createKey("Marshall", "123456");
Log.d("keyResult", keyResult);
keyTextView.setText(keyResult);
}
}

iOS

通过项目target的Linked frameworks and libraries把wallet.framework添加到项目,可以在iOS项目中对SDK的API进行调用:

#import "ViewController.h"
#import "Wallet/Wallet.h" // Gomobile bind generated framework @interface ViewController ()
@end @implementation ViewController @synthesize textLabel; - (void)loadView {
[super loadView];
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
WalletInitWallet(docPath);
textLabel.text = WalletCreateKey(@"kevin",@"123456");
} @end

Bytom移动端钱包SDK开发基础的更多相关文章

  1. Bytom 移动端钱包SDK FAQ

    比原链移动端钱包SDK项目地址:https://github.com/Bytom-Community/Bytom-Mobile-Wallet-SDK 1.客户端钱包SDK需要实现哪些功能? 创建密钥. ...

  2. 25-ESP8266 SDK开发基础入门篇--控制WIFI连接路由器

    https://www.cnblogs.com/yangfengwu/p/11324411.html 说个事情,现在SDK的版本已经出到3.0了,但是我还是使用2.0 如果只是为了学习研究   选择3 ...

  3. 16-ESP8266 SDK开发基础入门篇--TCP 服务器 非RTOS运行版,串口透传(串口回调函数处理版)

    https://www.cnblogs.com/yangfengwu/p/11105466.html 其实官方给的RTOS的版本就是在原先非RTOS版本上增加的 https://www.cnblogs ...

  4. 基于Unity3D 的Vuforia SDK开发基础教程

    最新博客地址已转到: http://blog.csdn.net/zzlyw?viewmode=contents   ------------------------------------------ ...

  5. 1-ESP8266 SDK开发基础入门篇--开发环境搭建

    因为今天终于做好了自己的另一块工控板,所以我就开始写基础公开篇的内容,希望自己小小的努力能够帮到大家 自己做的另一块板子 https://www.cnblogs.com/yangfengwu/cate ...

  6. 28-ESP8266 SDK开发基础入门篇--编写wifi模块TCP 客户端程序(官方API版,非RTOS版)

    https://www.cnblogs.com/yangfengwu/p/11432795.html 注:这节实现的功能是WIFI模块作为TCP 客户端,连接咱的TCP服务器,然后实现透传 本来想着做 ...

  7. 26-ESP8266 SDK开发基础入门篇--编写WIFI模块 SmartConfig/Airkiss 一键配网

    https://www.cnblogs.com/yangfengwu/p/11427504.html SmartConfig/Airkiss 配网需要APP/微信公众号,这节大家先使用我做好的APP/ ...

  8. 24-ESP8266 SDK开发基础入门篇--Android TCP客户端.控制 Wi-Fi输出PWM的占空比,调节LED亮度

    https://www.cnblogs.com/yangfengwu/p/11204436.html 刚才有人说需要点鸡汤.... 我想想哈;我还没问关于哪方面的鸡汤呢!!! 我所一直走的路线 第一: ...

  9. 18-ESP8266 SDK开发基础入门篇--TCP 服务器 RTOS版,串口透传,TCP客户端控制LED

    https://www.cnblogs.com/yangfengwu/p/11112015.html 先规定一下协议 aa 55 02 01 F1 4C 控制LED点亮  F1 4C为CRC高位和低位 ...

随机推荐

  1. 【转】 如何导入excel数据到数据库,并解决导入时间格式问题

    在办公环境下,经常会用到处理excel数据,如果用写程序导入excel数据到数据库那就太麻烦了,涉及解析excel,还要各种格式问题,下面简单利用数据库本身支持的功能解决这类导入问题. 准备 创建表 ...

  2. Python 3 -- 数据结构(list, dict, set,tuple )

    看了<Head First Python>后,觉得写的很不错,适合新手.此处为读书笔记,方便日后查看. Python 提供了4中数据结构:list,dict,set,tuple. 每种结构 ...

  3. 【Hadoop学习之十三】MapReduce案例分析五-ItemCF

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 推荐系统——协同过滤(Collab ...

  4. Python这么热,要不要追赶Python学习热潮?

    Python这么热,要不要追赶Python学习热潮? Python 可以用来做什么?在我看来,基本上可以不负责任地认为,Python 可以做任何事情.无论是从入门级选手到专业级选手都在做的爬虫,还是W ...

  5. AtCoder Beginner Contest 082 A - Round Up the Mean

    题目链接:https://abc082.contest.atcoder.jp/tasks/abc082_a Time limit : 2sec / Memory limit : 256MB Score ...

  6. Centos7 安装 apache + php7.0 环境

    安装apache rpm -qa|grep httpd   查看是否安装 yum install httpd  安装 service httpd start  启动服务 测试是否 启动       I ...

  7. easyui datagrid 遇到的坑 cannot read property ·· pageNum bug and so on

    1 本人刚刚接到一个bug,就是初始化时若设置了datagrid到指定页数,点击下一页显示不对,4 --> ‘4’+1=41的字符串形式,再点击超出页码范围直接到最后一页: 原因:因为 page ...

  8. getElementsByClassName方法的封装

    Element.prototype.getElementsByClassName = function(searchClass,node,tag){ if(document.getElementsBy ...

  9. MyEclipse 10.7(版本:eclipse 3.7.x-Indigo系列)安装activiti-eclipse-plugin插件(流程设计器)

    基本信息 1.本机MyEclipse 10.7菜单[Help->About MyEclipse Enterprise Workbench]的版本信息: MyEclipse Enterprise ...

  10. Golang对文件读写操作

    package main import ( "bufio" "fmt" "io" "os" ) //写 func Wri ...