Skip to content

Commit 6e2fb0b

Browse files
committed
Multisig: Generalized for any multisig
1 parent 41f9b20 commit 6e2fb0b

File tree

4 files changed

+76
-43
lines changed

4 files changed

+76
-43
lines changed

lib-api/src/main/java/org/ergoplatform/appkit/MultisigTransaction.java

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,55 @@
55
/**
66
* EIP-41/EIP-11 compliant multi sig transaction
77
*/
8-
public class MultisigTransaction {
8+
public abstract class MultisigTransaction {
99

1010
/**
1111
* @return transaction that is going to be signed
1212
*/
13-
public Transaction getTransaction() {
14-
throw new UnsupportedOperationException();
15-
}
16-
17-
/**
18-
* @return multisig address this transaction was created for
19-
*/
20-
public MultisigAddress getMultisigAddress() {
21-
throw new UnsupportedOperationException();
22-
}
13+
abstract public ReducedTransaction getTransaction();
2314

2415
/**
25-
* adds a new commitment to this multisig transaction
16+
* adds a new hint to this multisig transaction
2617
* @param prover to add commitment for
2718
*/
28-
public void addCommitment(ErgoProver prover) {
29-
throw new UnsupportedOperationException();
30-
}
19+
abstract public void addHint(ErgoProver prover);
3120

3221
/**
33-
* adds the commitments not present on this instance from another multisig transaction instance
22+
* adds the hints not present on this instance from another multisig transaction instance
3423
* for the same transaction.
3524
*/
36-
public void addCommitments(MultisigTransaction other) {
37-
throw new UnsupportedOperationException();
38-
}
25+
abstract public void mergeHints(MultisigTransaction other);
3926

4027
/**
41-
* @return list of participants that added a commitment for the transaction
28+
* adds the hints not present on this instance from the EIP-11 json
4229
*/
43-
public List<Address> getCommitingParticipants() {
44-
throw new UnsupportedOperationException();
45-
}
46-
47-
public boolean hasEnoughCommitments() {
48-
throw new UnsupportedOperationException();
49-
}
30+
abstract public void mergeHints(String json);
5031

5132
/**
52-
* @return the signed transaction if enough commitments are available
53-
* @throws IllegalStateException if {@link #hasEnoughCommitments()} is false
33+
* @return list of participants that added a hint for the transaction
5434
*/
55-
public SignedTransaction toSignedTransaction() {
56-
throw new UnsupportedOperationException();
57-
}
35+
abstract public List<Address> getCommitingParticipants();
36+
/**
37+
* @return true if SignedTransaction can be built
38+
*/
39+
abstract public boolean isHintBagComplete();
5840

5941
/**
60-
* @return EIP-11 compliant json string to transfer the partially signed transaction to the
61-
* next particpant
42+
* @return the signed transaction if enough commitments are available
43+
* @throws IllegalStateException if {@link #isHintBagComplete()} is false
6244
*/
63-
public String toJson() {
64-
throw new UnsupportedOperationException();
65-
}
45+
abstract public SignedTransaction toSignedTransaction();
6646

6747
/**
68-
* constructs a multi sig transaction from an unsigned transaction. The first multi sig address
69-
* in input boxes is used.
48+
* @return EIP-11 compliant json string to transfer the partially signed transaction to the
49+
* next participant
7050
*/
71-
public static MultisigTransaction fromTransaction(UnsignedTransaction transaction) {
72-
throw new UnsupportedOperationException();
73-
}
51+
abstract public String hintsToJson();
7452

7553
/**
7654
* constructs a multi sig transaction from a reduced transaction
7755
*/
78-
public static MultisigTransaction fromTransaction(ReducedTransaction transaction, MultisigAddress address) {
56+
public static MultisigTransaction fromTransaction(ReducedTransaction transaction) {
7957
throw new UnsupportedOperationException();
8058
}
8159

lib-api/src/main/java/org/ergoplatform/appkit/ReducedTransaction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ public interface ReducedTransaction extends Transaction {
2121
* Returns the serialized bytes of this transaction.
2222
*/
2323
byte[] toBytes();
24+
25+
/**
26+
* @return tree of participants required or able to sign for the transaction
27+
*/
28+
SigningParticipants getSignersRequired();
2429
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.ergoplatform.appkit;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Participants able to sign for a {@link ReducedTransaction}
7+
*/
8+
abstract public class SigningParticipants {
9+
10+
/**
11+
* @return true if multiple signers are needed
12+
*/
13+
abstract public boolean isMultisig();
14+
15+
/**
16+
* Multisig requirement, k-out-of-n
17+
*/
18+
public static class MultisigRequirement extends SigningParticipants {
19+
public final int hintsNeeded;
20+
public final List<SigningParticipants> hintbag;
21+
22+
public MultisigRequirement(int hintsNeeded, List<SigningParticipants> hintbag) {
23+
this.hintsNeeded = hintsNeeded;
24+
this.hintbag = hintbag;
25+
}
26+
27+
@Override
28+
public boolean isMultisig() {
29+
return hintsNeeded > 1;
30+
}
31+
}
32+
33+
public static class SingleSigner extends SigningParticipants {
34+
public final Address address;
35+
36+
public SingleSigner(Address address) {
37+
this.address = address;
38+
}
39+
40+
@Override
41+
public boolean isMultisig() {
42+
return false;
43+
}
44+
}
45+
}

lib-impl/src/main/java/org/ergoplatform/appkit/impl/ReducedTransactionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public byte[] toBytes() {
6868
return w.toBytes();
6969
}
7070

71+
@Override
72+
public SigningParticipants getSignersRequired() {
73+
throw new UnsupportedOperationException();
74+
}
75+
7176
@Override
7277
public int hashCode() {
7378
return _tx.hashCode();

0 commit comments

Comments
 (0)