Skip to content

Commit

Permalink
add basic support for tx building (#1)
Browse files Browse the repository at this point in the history
* add tx_input, tx_output, tx_hash for Android

* update repo according to last changes in cardano-serialization-lib. Add BigNum. Update tests

* add missing functions on iOS

* add basic impl of ByronAddress. Add Coin as a wrapper of BigNum

* add LinearFee

* complete transactionInput/Output

* add Bip32PrivateKey

* add witness-related functions
  • Loading branch information
v-almonacid committed Jul 25, 2020
1 parent 7650afd commit 14db56b
Show file tree
Hide file tree
Showing 49 changed files with 3,228 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,133 @@ public String getName() {
return "HaskellShelley";
}

// Address
// Utils

@ReactMethod
public final void addressFromBytes(String bytes, Promise promise) {
public final void makeIcarusBootstrapWitness(String txBodyHash, String addr, String key, Promise promise) {
Native.I
.addressFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.makeIcarusBootstrapWitness(new RPtr(txBodyHash), new RPtr(addr), new RPtr(key))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void makeVkeyWitness(String txBodyHash, String sk, Promise promise) {
Native.I
.makeVkeyWitness(new RPtr(txBodyHash), new RPtr(sk))
.map(RPtr::toJs)
.pour(promise);
}

// BigNum

@ReactMethod
public final void bigNumFromStr(String string, Promise promise) {
Native.I
.bigNumFromStr(string)
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void bigNumToStr(String bigNum, Promise promise) {
Native.I
.bigNumToStr(new RPtr(bigNum))
.pour(promise);
}

// Bip32PrivateKey

@ReactMethod
public final void bip32PrivateKeyDerive(String bip32PrivateKey, Double index, Promise promise) {
Native.I
.bip32PrivateKeyDerive(new RPtr(bip32PrivateKey), index.longValue())
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void bip32PrivateKeyGenerateEd25519Bip32(Promise promise) {
Native.I
.bip32PrivateKeyGenerateEd25519Bip32()
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void bip32PrivateKeyToRawKey(String bip32PrivateKey, Promise promise) {
Native.I
.bip32PrivateKeyToRawKey(new RPtr(bip32PrivateKey))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void bip32PrivateKeyToPublic(String bip32PrivateKey, Promise promise) {
Native.I
.bip32PrivateKeyToPublic(new RPtr(bip32PrivateKey))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void bip32PrivateKeyFromBytes(String bytes, Promise promise) {
Native.I
.bip32PrivateKeyFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void bip32PrivateKeyAsBytes(String bip32PrivateKey, Promise promise) {
Native.I
.bip32PrivateKeyAsBytes(new RPtr(bip32PrivateKey))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}

@ReactMethod
public final void bip32PrivateKeyFromBech32(String bech32Str, Promise promise) {
Native.I
.bip32PrivateKeyFromBech32(bech32Str)
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void bip32PrivateKeyToBech32(String bip32PrivateKey, Promise promise) {
Native.I
.bip32PrivateKeyToBech32(new RPtr(bip32PrivateKey))
.pour(promise);
}

@ReactMethod
public final void bip32PrivateKeyFromBip39Entropy(String entropy, String password, Promise promise) {
Native.I
.bip32PrivateKeyFromBip39Entropy(Base64.decode(entropy, Base64.DEFAULT), Base64.decode(password, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}

// ByronAddress

@ReactMethod
public final void byronAddressToBase58(String byronAddress, Promise promise) {
Native.I
.byronAddressToBase58(new RPtr(byronAddress))
.pour(promise);
}

@ReactMethod
public final void byronAddressFromBase58(String string, Promise promise) {
Native.I
.byronAddressFromBase58(string)
.map(RPtr::toJs)
.pour(promise);
}

// Address

@ReactMethod
public final void addressToBytes(String address, Promise promise) {
Native.I
Expand All @@ -41,30 +158,56 @@ public final void addressToBytes(String address, Promise promise) {
.pour(promise);
}

// AddrKeyHash
@ReactMethod
public final void addressFromBytes(String bytes, Promise promise) {
Native.I
.addressFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}

// Ed25519KeyHash

@ReactMethod
public final void ed25519KeyHashToBytes(String ed25519KeyHash, Promise promise) {
Native.I
.ed25519KeyHashToBytes(new RPtr(ed25519KeyHash))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}

@ReactMethod
public final void addrKeyHashFromBytes(String bytes, Promise promise) {
public final void ed25519KeyHashFromBytes(String bytes, Promise promise) {
Native.I
.addrKeyHashFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.ed25519KeyHashFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}

// TransactionHash

@ReactMethod
public final void addrKeyHashToBytes(String addrKeyHash, Promise promise) {
public final void transactionHashToBytes(String transactionHash, Promise promise) {
Native.I
.addrKeyHashToBytes(new RPtr(addrKeyHash))
.transactionHashToBytes(new RPtr(transactionHash))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}

@ReactMethod
public final void transactionHashFromBytes(String bytes, Promise promise) {
Native.I
.transactionHashFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}

// StakeCredential

@ReactMethod
public final void stakeCredentialFromKeyHash(String addrKeyHash, Promise promise) {
public final void stakeCredentialFromKeyHash(String keyHash, Promise promise) {
Native.I
.stakeCredentialFromKeyHash(new RPtr(addrKeyHash))
.stakeCredentialFromKeyHash(new RPtr(keyHash))
.map(RPtr::toJs)
.pour(promise);
}
Expand Down Expand Up @@ -129,11 +272,179 @@ public final void unitIntervalFromBytes(String bytes, Promise promise) {
}

@ReactMethod
public final void unitIntervalNew(Double index0, Double index1, Promise promise) {
public final void unitIntervalNew(String numerator, String denominator, Promise promise) {
Native.I
.unitIntervalNew(new RPtr(numerator), new RPtr(denominator))
.map(RPtr::toJs)
.pour(promise);
}

// TransactionInput

@ReactMethod
public final void transactionInputToBytes(String transactionInput, Promise promise) {
Native.I
.transactionInputToBytes(new RPtr(transactionInput))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}

@ReactMethod
public final void transactionInputFromBytes(String bytes, Promise promise) {
Native.I
.transactionInputFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void transactionInputTransactionId(String transactionInput, Promise promise) {
Native.I
.transactionInputTransactionId(new RPtr(transactionInput))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void transactionInputIndex(String transactionInput, Promise promise) {
Native.I
.unitIntervalNew(index0.longValue(), index1.longValue())
.transactionInputIndex(new RPtr(transactionInput))
.map(Long::intValue)
.pour(promise);
}

@ReactMethod
public final void transactionInputNew(String transactionId, Double index, Promise promise) {
Native.I
.transactionInputNew(new RPtr(transactionId), index.longValue())
.map(RPtr::toJs)
.pour(promise);
}

// TransactionOutput

@ReactMethod
public final void transactionOutputToBytes(String transactionOutput, Promise promise) {
Native.I
.transactionOutputToBytes(new RPtr(transactionOutput))
.map(bytes -> Base64.encodeToString(bytes, Base64.DEFAULT))
.pour(promise);
}

@ReactMethod
public final void transactionOutputFromBytes(String bytes, Promise promise) {
Native.I
.transactionOutputFromBytes(Base64.decode(bytes, Base64.DEFAULT))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void transactionOutputNew(String address, String amount, Promise promise) {
Native.I
.transactionOutputNew(new RPtr(address), new RPtr(amount))
.map(RPtr::toJs)
.pour(promise);
}

// LinearFee

@ReactMethod
public final void linearFeeCoefficient(String linearFee, Promise promise) {
Native.I
.linearFeeCoefficient(new RPtr(linearFee))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void linearFeeConstant(String linearFee, Promise promise) {
Native.I
.linearFeeConstant(new RPtr(linearFee))
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void linearFeeNew(String coefficient, String constant, Promise promise) {
Native.I
.linearFeeNew(new RPtr(coefficient), new RPtr(constant))
.map(RPtr::toJs)
.pour(promise);
}

// Vkeywitnesses

@ReactMethod
public final void vkeywitnessesNew(Promise promise) {
Native.I
.vkeywitnessesNew()
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void vkeywitnessesLen(String vkwitnesses, Promise promise) {
Native.I
.vkeywitnessesLen(new RPtr(vkwitnesses))
.map(Long::intValue)
.pour(promise);
}

@ReactMethod
public final void vkeywitnessesAdd(String vkwitnesses, String item, Promise promise) {
Native.I
.vkeywitnessesAdd(new RPtr(vkwitnesses), new RPtr(item))
.pour(promise);
}

// BootstrapWitnesses

@ReactMethod
public final void bootstrapWitnessesNew(Promise promise) {
Native.I
.bootstrapWitnessesNew()
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void bootstrapWitnessesLen(String witnesses, Promise promise) {
Native.I
.bootstrapWitnessesLen(new RPtr(witnesses))
.map(Long::intValue)
.pour(promise);
}

@ReactMethod
public final void bootstrapWitnessesAdd(String witnesses, String item, Promise promise) {
Native.I
.bootstrapWitnessesAdd(new RPtr(witnesses), new RPtr(item))
.pour(promise);
}

// TransactionWitnessSet

@ReactMethod
public final void transactionWitnessSetNew(Promise promise) {
Native.I
.transactionWitnessSetNew()
.map(RPtr::toJs)
.pour(promise);
}

@ReactMethod
public final void transactionWitnessSetSetVkeys(String witnessSet, String vkeys, Promise promise) {
Native.I
.transactionWitnessSetSetVkeys(new RPtr(witnessSet), new RPtr(vkeys))
.pour(promise);
}

@ReactMethod
public final void transactionWitnessSetSetBootstraps(String witnessSet, String bootstraps, Promise promise) {
Native.I
.transactionWitnessSetSetBootstraps(new RPtr(witnessSet), new RPtr(bootstraps))
.pour(promise);
}

}

0 comments on commit 14db56b

Please sign in to comment.