Skip to content
Snippets Groups Projects
Select Git revision
  • 2516166867a1fa3f0343400af3ff801fd31a5416
  • main default protected
2 results

README.md

Blame
  • Wallet.java NaN GiB
    package fr.miage;
    
    import java.security.KeyPair;
    import java.security.KeyPairGenerator;
    import java.security.NoSuchAlgorithmException;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
    
    public class Wallet {
        private KeyPair keyPair;
        private List<UTxO> utxos;
        private String name; // temp
    
        public Wallet(String name) throws NoSuchAlgorithmException, InterruptedException {
            this.name = name;
            this.keyPair = generateKeyPair();
            this.utxos = new ArrayList<UTxO>();
        }
    
        public KeyPair generateKeyPair() throws NoSuchAlgorithmException {
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
            keyPairGenerator.initialize(2048);
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            return keyPair;
        }
    
        @SuppressWarnings("unchecked")
        public List<UTxO> getUTxOsForTransaction(double amount) {
            List<UTxO> result = new ArrayList<>();
            double res = 0;
            boolean stop = false;
            Collections.sort(this.utxos);
            for (UTxO utxo : this.utxos) {
                if (res >= amount) {
                    stop = true;
                }
                if (res < amount && !stop) {
                    result.add(utxo);
                    res += utxo.getMontant();
                }
            }
            utxos.removeAll(result);
    
            if (res < amount) {
                return null;
            } else {
                return result;
            }
    
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public List<UTxO> getUtxos() {
            return this.utxos;
        }
    
        public void addUTxO(UTxO utxo) {
            this.utxos.add(utxo);
        }
    
        @Override
        public String toString() {
            return "Wallet [keyPair=" + keyPair + ", utxos=" + utxos + ", name=" + name + "]";
        }
    
        public KeyPair getKeyPair() {
            return keyPair;
        }
    
        public void setKeyPair(KeyPair keyPair) {
            this.keyPair = keyPair;
        }
    
    }