Search in sources :

Example 1 with HashLiteral

use of it.unica.tcs.bitcoinTM.HashLiteral in project balzac by balzac-lang.

the class ASTUtils method objectToExpression.

public Expression objectToExpression(Object value) {
    if (value instanceof Long) {
        NumberLiteral res = BitcoinTMFactory.eINSTANCE.createNumberLiteral();
        res.setValue((Long) value);
        return res;
    } else if (value instanceof String) {
        StringLiteral res = BitcoinTMFactory.eINSTANCE.createStringLiteral();
        res.setValue((String) value);
        return res;
    } else if (value instanceof Boolean) {
        BooleanLiteral res = BitcoinTMFactory.eINSTANCE.createBooleanLiteral();
        res.setTrue((Boolean) value);
        return res;
    } else if (value instanceof Hash) {
        HashLiteral res = BitcoinTMFactory.eINSTANCE.createHashLiteral();
        res.setValue(((Hash) value).getBytes());
        return res;
    } else if (value instanceof DumpedPrivateKey) {
        KeyLiteral res = BitcoinTMFactory.eINSTANCE.createKeyLiteral();
        res.setValue(((DumpedPrivateKey) value).toBase58());
        return res;
    } else if (value instanceof TransactionSignature) {
        SignatureLiteral res = BitcoinTMFactory.eINSTANCE.createSignatureLiteral();
        res.setValue(BitcoinUtils.encode(((TransactionSignature) value).encodeToBitcoin()));
        return res;
    } else {
        throw new IllegalStateException("Unexpected type " + value.getClass());
    }
}
Also used : BooleanLiteral(it.unica.tcs.bitcoinTM.BooleanLiteral) TransactionSignature(org.bitcoinj.crypto.TransactionSignature) SignatureLiteral(it.unica.tcs.bitcoinTM.SignatureLiteral) Hash(it.unica.tcs.lib.Hash) SigHash(org.bitcoinj.core.Transaction.SigHash) StringLiteral(it.unica.tcs.bitcoinTM.StringLiteral) HashLiteral(it.unica.tcs.bitcoinTM.HashLiteral) KeyLiteral(it.unica.tcs.bitcoinTM.KeyLiteral) DumpedPrivateKey(org.bitcoinj.core.DumpedPrivateKey) NumberLiteral(it.unica.tcs.bitcoinTM.NumberLiteral)

Aggregations

BooleanLiteral (it.unica.tcs.bitcoinTM.BooleanLiteral)1 HashLiteral (it.unica.tcs.bitcoinTM.HashLiteral)1 KeyLiteral (it.unica.tcs.bitcoinTM.KeyLiteral)1 NumberLiteral (it.unica.tcs.bitcoinTM.NumberLiteral)1 SignatureLiteral (it.unica.tcs.bitcoinTM.SignatureLiteral)1 StringLiteral (it.unica.tcs.bitcoinTM.StringLiteral)1 Hash (it.unica.tcs.lib.Hash)1 DumpedPrivateKey (org.bitcoinj.core.DumpedPrivateKey)1 SigHash (org.bitcoinj.core.Transaction.SigHash)1 TransactionSignature (org.bitcoinj.crypto.TransactionSignature)1