ICAP互换客户端地址协议iOS实现示例
之前我寫了一篇關(guān)于ICAP: 互換客戶端地址協(xié)議的文章。文章中介紹和詳細解析了關(guān)于ICAP協(xié)議算法,并給出Go語言版本的具體實現(xiàn)。實際上以太坊全節(jié)點Geth提供了WEB3接口,來轉(zhuǎn)換ICAP格式地址(web3.fromICAP("XE86G29C8IV34UOJMYWHGDSGME33YKEC3QO"))。
> web3 {... ...BigNumber: function a(e,n),fromICAP: function(icap),isAddress: function(address),isChecksumAddress: function(address),sha3: function(string, options),toBigNumber: function(number),toChecksumAddress: function(address)... ... }> web3.fromICAP("XE86G29C8IV34UOJMYWHGDSGME33YKEC3QO") "8982b139b2fca9452eae977827fb12280a9a1bf0" >不過這種方式轉(zhuǎn)換ICAP格式地址,在客戶端與服務(wù)端交互上有些繁瑣,特別是在手機端操作時。手機端完全可以利用每一臺終端設(shè)備來處理這個轉(zhuǎn)換工作,直接將ICAP格式地址發(fā)送給服務(wù)端處理全部轉(zhuǎn)換邏輯顯得沒有必要。另外,web3.fromICAP只能轉(zhuǎn)換出非含校驗和的以太坊賬戶地址,仍需要調(diào)用web3.toChecksumAddress來完成剩余工作。
因此,在這個大前提下,BOX企業(yè)數(shù)字資產(chǎn)保險箱 員工版APP開發(fā)了基于ICAP協(xié)議算法的一套iOS庫。該庫可以直接在手機端完成轉(zhuǎn)換工作,不需要與后端web3接口交互。可能Geth已有iOS版本相關(guān)的庫(pod Geth),不過由于這個庫太大,一直沒有下載成功,也沒有辦法驗證其功能是否包含ICAP功能。使用本庫的還有一個好處是簡單明了,不必依賴大型庫,同時轉(zhuǎn)換出的以太坊地址支持checksum。
我是一位Gopher,淺嘗iOS,代碼目標不是做一個完整的手機APP,旨在實現(xiàn)ICAP格式協(xié)議地址轉(zhuǎn)換成以太坊賬戶地址。代碼在這里被找到 https://github.com/alphaqiu/i...
icap-ios
接口定義:
@interface ICAP :NSObject /*** @brief convert icap string to ethereum account address.** example code:** ICAP *decoder = [[ICAP alloc] init];* NSError *error;* NSString icapString = @"XE86G29C8IV34UOJMYWHGDSGME33YKEC3QO";* [decoder addressConvertFrom:icapString didFailedWithError:&error];* if (error != nil) {* NSLog(@"Convert from ICAP failed, cause:%@", error);* }** @param icapString *NSString* @param error **NSError when invoked the function, if this reference error not nil, then the renturn string is nil.* @return *NSString the ethereum account address.*/ -(NSString *) addressConvertFrom:(NSString *)icapString didFailedWithError:(NSError **)error; @end使用方法:
ICAP *decoder = [[ICAP alloc] init]; NSError *error; [decoder addressConvertFrom:@"XE86G29C8IV34UOJMYWHGDSGME33YKEC3QO" didFailedWithError:&error]; if (error != nil) {NSLog(@"Convert from ICAP failed, cause:%@", error); }工程依賴庫安裝:
# Uncomment the next line to define a global platform for your project # platform :ios, '9.0'target 'prog3' do# Uncomment the next line if you're using Swift or would like to use dynamic frameworksuse_frameworks!pod 'JKBigInteger', '~> 0.0.1'# Pods for prog3end pod install總結(jié)
以上是生活随笔為你收集整理的ICAP互换客户端地址协议iOS实现示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: power BI 中x轴日期值显示英文改
- 下一篇: hadoop暂时/永久关闭安全模式