Skip to content

Commit

Permalink
sup kin
Browse files Browse the repository at this point in the history
  • Loading branch information
pengpengliu committed Jun 28, 2020
1 parent ef7ebe0 commit 131be15
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/org/bitcorej/chain/ChainStateProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.bitcorej.chain.ripple.RippleStateProvider;
import org.bitcorej.chain.rvc.RVCStateProvider;
import org.bitcorej.chain.rvn.RVNStateProvider;
import org.bitcorej.chain.stellar.KINStateProvider;
import org.bitcorej.chain.stellar.StellarStateProvider;
import org.bitcorej.chain.stg.STGStateProvider;
import org.bitcorej.chain.trx.TRXStateProvider;
Expand Down Expand Up @@ -173,6 +174,9 @@ public class ChainStateProxy implements ChainState, UTXOState, USDTState, XMRSta
DIVIStateProvider divi = new DIVIStateProvider(Network.MAIN);
services.put("DIVI", divi);
services.put("DIVI_MAIN", divi);
KINStateProvider kin = new KINStateProvider(Network.MAIN);
services.put("KIN", kin);
services.put("KI_MAIN", kin);
}

private ChainState provider;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.bitcorej.chain.stellar;

import org.bitcorej.core.Network;
import org.bitcorej.utils.NumericUtil;
import org.json.JSONObject;
import org.stellar.sdk.*;

import java.math.BigDecimal;
import java.util.List;

public class KINStateProvider extends StellarStateProvider {
public KINStateProvider(Network network) {
super(network);
}

@Override
protected void switchNetwork() {
org.stellar.sdk.Network.use(new org.stellar.sdk.Network("Kin Mainnet ; December 2018"));
}

@Override
public String signRawTransaction(String rawTx, List<String> keys) {
switchNetwork();
JSONObject jsonObject = new JSONObject(rawTx);
String to = jsonObject.getString("to");
String type = jsonObject.getString("type");
Long sequence = Long.parseLong(jsonObject.getString("sequence"));
int fee = jsonObject.getInt("fee");
String memo = jsonObject.getString("memo");
// The KIN decimals is 5 (XLM is 7)
BigDecimal amount = new BigDecimal(jsonObject.getString("amount")).divide(new BigDecimal(100));
org.stellar.sdk.KeyPair source = org.stellar.sdk.KeyPair.fromSecretSeed(keys.get(0));
org.stellar.sdk.KeyPair destination = org.stellar.sdk.KeyPair.fromAccountId(to);
Asset asset = new AssetTypeNative();
Operation op;
if (type.equals("payment")) {
op = new PaymentOperation.Builder(destination, asset, amount.toString()).build();
} else if (type.equals("create_account")) {
op = new CreateAccountOperation.Builder(destination, amount.toString()).build();
} else {
throw new RuntimeException("no sup op");
}
org.stellar.sdk.Transaction transaction = new org.stellar.sdk.Transaction.Builder(new Account(source, sequence))
.addOperation(op)
.setOperationFee(fee)
.addMemo(Memo.text(memo))
.setTimeout(0)
.build();
transaction.sign(source);
JSONObject packedTx = new JSONObject();
packedTx.put("XDR", transaction.toEnvelopeXdrBase64());
return packedTx.toString();
}
}

0 comments on commit 131be15

Please sign in to comment.