/RenVMSwift

An implementation of RenVM written in pure Swift

Primary LanguageSwiftMIT LicenseMIT

RenSwift

CI Status Version License Platform

How to use

Sending

// define ChainProvider
class SolanaChainProvider: ChainProvider {
    func getAccount() async throws -> (publicKey: Data, secret: Data) {
        let account = // account in solana chain
        return (publicKey: account.publicKey.data, secret: account.secretKey)
    }
    
    func load() async throws -> RenVMChainType {
        try await SolanaChain.load(
            client: renRPCClient,
            apiClient: solanaAPIClient,
            blockchainClient: BlockchainClient(apiClient: solanaAPIClient)
        )
    }
}

// define persistentStore for re-release transaction in case of failure
class PersistentStore: BurnAndReleasePersistentStore {
    private var fileStore = SomeFileStore()
    
    func getNonReleasedTransactions() -> [BurnAndRelease.BurnDetails] {
        fileStore.getSavedTxs()
    }
    
    func persistNonReleasedTransactions(_ transaction: BurnAndRelease.BurnDetails) {
        fileStore.write(transaction)
    }
    
    func markAsReleased(_ transaction: BurnAndRelease.BurnDetails) {
        fileStore.removeAll(where: {$0.confirmedSignature == transaction.confirmedSignature})
    }
}

// create instance of service
let service = BurnAndReleaseServiceImpl(
    rpcClient: renRPCClient,
    chainProvider: SolanaChainProvider(),
    destinationChain: .bitcoin,
    persistentStore: PersistentStore(),
    version: "1"
)

// resume all failured transaction from last time
service.resume()

// burn and release
let tx = try await service.burnAndRelease(recipient: "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt", amount: 0.0001.toLamport(decimals: 8)) // 0.0001 renBTC
print(tx)

Requirements

Installation

RenVMSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RenVMSwift', '~> 3.0.0'

Author

Chung Tran, bigearsenal@gmail.com

License

RenSwift is available under the MIT license. See the LICENSE file for more info.