Closed TheArhaam closed 3 years ago
Which version of react native are you using?
Could it be related to this issue? Please check if you can reproduce the problem in version 0.61.5 of RN
@TimoGlastra Well myreact-native
version is 0.63.2
, I will try using 0.61.5
and see if the issue persists.
Will get back to you shortly, Thank you 😄
@TimoGlastra I am facing the same issue with react-native
version 0.61.5
ðŸ˜
Have you tested out the rn-indy-sdk
completely in your fork?
I've referred to a couple of examples of the Indy SDK and it doesn't seem like I'm missing anything but here is the code I'm currently using:
import React, { Component } from "react";
import { ScrollView, View, Text, TouchableOpacity, StyleSheet } from "react-native";
import indy from 'rn-indy-sdk';
import RNFS from 'react-native-fs';
import axios from "axios";
class App extends Component {
constructor(props) {
super(props);
this.state = {
wallethandle: null,
poolhandle: null
}
}
// =========================================
// FILE SYSTEM
// =========================================
getFiles = () => {
RNFS.readDir(RNFS.DocumentDirectoryPath)
.then((result) => {
console.log('GOT RESULT', result);
// stat the first file
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.catch((err) => {
console.log(err.message, err.code);
});
}
createGenFile = async () => {
console.log("CREATE GEN FILE")
let genesis;
// get genesis transactions
await axios.get('http://dev.greenlight.bcovrin.vonx.io/genesis')
.then(async (res) => {
genesis = res.data;
console.log("==================================")
console.log("GENESIS")
console.log("==================================")
console.log(genesis)
// write genesis to file
var path = RNFS.DocumentDirectoryPath + '/indy_genesis_transactions.txt';
console.log("PATH: " + path)
await RNFS.writeFile(path, genesis, 'utf8')
.then((success) => {
console.log('[GEN FILE] WRITTEN!');
})
.catch((err) => {
console.log(err.message);
});
})
.catch((err) => {
console.log('[AXIOS] ERR: ' + err);
})
}
// =========================================
// POOL
// =========================================
createPool = async () => {
console.log("CREATE POOL LEDGER CONFIG")
var path = RNFS.DocumentDirectoryPath + '/indy_genesis_transactions.txt';
const config = {
genesis_txn: path,
}
console.log("CONFIG: " + JSON.stringify(config))
const result =
await indy.createPoolLedgerConfig('test9', JSON.stringify(config))
.then(async (res) => {
console.log('POOL LEDGER CONFIG CREATED')
console.log('Result: ' + res)
})
.catch((err) => {
console.log("ERR: " + err)
});
}
openPool = async () => {
console.log("OPEN POOL LEDGER")
var path = RNFS.DocumentDirectoryPath + '/indy_genesis_transactions.txt';
const config = {
genesis_txn: path,
}
console.log("CONFIG: " + JSON.stringify(config))
await indy.openPoolLedger('test9', '{}')
.then((res) => {
console.log('POOL LEDGER OPENED');
console.log('POOL HANDLE: ' + res);
this.setState({
poolhandle: result
})
})
.catch((err) => {
console.log('OPEN POOL ERR: ' + err);
});
}
render() {
return (
<ScrollView>
{/* CREATE GEN FILE */}
<TouchableOpacity onPress={() => { this.createGenFile() }}>
<View style={styles.bttn} >
<Text style={styles.txt}>Create Gen File</Text>
</View>
</TouchableOpacity>
{/* GET FILES */}
<TouchableOpacity onPress={() => { this.getFiles() }}>
<View style={styles.bttn} >
<Text style={styles.txt}>Get Files</Text>
</View>
</TouchableOpacity>
{/* CREATE POOL LEDGER CONFIG */}
<TouchableOpacity onPress={() => { this.createPool() }}>
<View style={styles.bttn} >
<Text style={styles.txt}>Create Pool Ledger Config</Text>
</View>
</TouchableOpacity>
{/* OPEN POOL LEDGER */}
<TouchableOpacity onPress={() => { this.openPool() }}>
<View style={styles.bttn} >
<Text style={styles.txt}>Open Pool Ledger</Text>
</View>
</TouchableOpacity>
</ScrollView>
);
}
}
// STYLES - STYLESHEET
const styles = StyleSheet.create({
bttn: {
backgroundColor: 'lightblue',
padding: 20,
margin: 20
},
txt: {
color: 'black',
textAlign: 'center'
}
});
export default App;
NOTE: I've tried the following for openPoolLedger()
:
indy.openPoolLedger('test', JSON.stringify(config))
indy.openPoolLedger('test', null)
indy.openPoolLedger('test', '{}')
Not really sure which one is correct.I'm able to reproduce your error in RN > 0.61.5, but not 0.61.5. However i'm using the master version of rn-indy-sdk instead of the NPM version. So could you check once again, but this time with version 0.65.1
and the master branch? To run with the master branch:
git clone https://github.com/AbsaOss/rn-indy-sdk
cd rn-indy-sdk
yarn install
yarn pack
this will output a file rn-indy-sdk-v0.1.3.tgz
that you can then add to your react native project. Inside your react native project run:
yarn add file:../path/to/rn-indy-sdk/rn-indy-sdk-v0.1.3.tgz
Do note that the master branch doesn't expect strings as parameters, but JSON objects:
// NPM rn-indy-sdk
indy.createPoolLedgerConfig('test9', JSON.stringify(config))
// master rn-indy-sdk
indy.createPoolLedgerConfig('test9', config)
For the openPoolLedger it is fine to call without a second parameter (openPoolLedger('test9')
). Also make sure to call setProtocolVersion(2)
before opening the pool.
Let me know if you can get it to work!
@TimoGlastra Thank you for all your help, turns out all I had to do was add indy.setProtocolVersion(2)
😅. It's working now, I was able to get the Pool Handle. I'm not sure what this function does, I would appreciate it if you could give me a brief explanation 😅
Also, would you recommend I use the master branch going forward? Or should I stick to the current npm package?
For the protocol version, see the indy-sdk docs. It defaults to 1. From the docs: "Protocol version will be used: 1 - for Indy Node 1.3 2 - for Indy Node 1.4 and greater". I believe indy node version is already at something like level 1.12, so you'll probably always need version 2.
For using the master branch: I would say yes at the moment. The NPM package isn't updated in a while, and as the package is in early stage development you'll probably get the fixes quicker
@TimoGlastra Alright, thank you so much for all the help. 😄
So I've run the following and it worked:
However, I'm not getting any response (Pool Handle) when opening the pool ledger, I've tried the following:
indy.openPoolLedger('test', JSON.stringify(config))
indy.openPoolLedger('test', null)
indy.openPoolLedger('test', '{}')