Skip to content

Commit

Permalink
v0 transaction succesfully parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-sekanina committed Mar 18, 2022
1 parent cdbb9e1 commit 6414362
Show file tree
Hide file tree
Showing 18 changed files with 578 additions and 467 deletions.
9 changes: 9 additions & 0 deletions .idea/PSBT.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

299 changes: 153 additions & 146 deletions applet/build/reports/tests/test/classes/tests.AppletTest.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions applet/build/reports/tests/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h1>Test Summary</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.279s</div>
<div class="counter">0.157s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -85,7 +85,7 @@ <h2>Packages</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0.279s</td>
<td>0.157s</td>
<td class="success">100%</td>
</tr>
</tbody>
Expand All @@ -112,7 +112,7 @@ <h2>Classes</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0.279s</td>
<td>0.157s</td>
<td class="success">100%</td>
</tr>
</tbody>
Expand All @@ -126,7 +126,7 @@ <h2>Classes</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 6.6</a> at Feb 24, 2022, 1:55:40 AM</p>
<a href="http://www.gradle.org">Gradle 6.6</a> at 18 Mar 2022, 4:14:08 PM</p>
</div>
</div>
</body>
Expand Down
6 changes: 3 additions & 3 deletions applet/build/reports/tests/test/packages/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1>Package tests</h1>
</td>
<td>
<div class="infoBox" id="duration">
<div class="counter">0.279s</div>
<div class="counter">0.157s</div>
<p>duration</p>
</div>
</td>
Expand Down Expand Up @@ -83,7 +83,7 @@ <h2>Classes</h2>
<td>1</td>
<td>0</td>
<td>0</td>
<td>0.279s</td>
<td>0.157s</td>
<td class="success">100%</td>
</tr>
</table>
Expand All @@ -96,7 +96,7 @@ <h2>Classes</h2>
<input id="line-wrapping-toggle" type="checkbox" autocomplete="off"/>
</label>
</div>Generated by
<a href="http://www.gradle.org">Gradle 6.6</a> at Feb 24, 2022, 1:55:40 AM</p>
<a href="http://www.gradle.org">Gradle 6.6</a> at 18 Mar 2022, 4:14:08 PM</p>
</div>
</div>
</body>
Expand Down
290 changes: 153 additions & 137 deletions applet/build/test-results/test/TEST-tests.AppletTest.xml

Large diffs are not rendered by default.

288 changes: 154 additions & 134 deletions applet/build/test-results/test/binary/output.bin

Large diffs are not rendered by default.

Binary file modified applet/build/test-results/test/binary/output.bin.idx
Binary file not shown.
Binary file modified applet/build/test-results/test/binary/results.bin
Binary file not shown.
22 changes: 10 additions & 12 deletions applet/build/tmp/compileJava/source-classes-mapping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,27 @@ applet/Key.java
applet.Key
applet/Value.java
applet.Value
applet/PGU_TX_keypair.java
applet.PGU_TX_keypair
applet/AppletInstructions.java
applet.AppletInstructions
applet/GeneralMap.java
applet.GeneralMap
applet/AppletInstructions.java
applet.AppletInstructions
applet/SekripkInstructions.java
applet.SekripkInstructions
applet/KeyPair.java
applet.KeyPair
applet/GlobalMap.java
applet.GlobalMap
applet/SecretAndTimeStorage.java
applet.SecretAndTimeStorage
applet/GlobalUnsignedTX.java
applet.GlobalUnsignedTX
applet/PSBT.java
applet.PSBT
applet/GlobalUnsignedTXOutput.java
applet.GlobalUnsignedTXOutput
applet/GlobalUnsignedTXInput.java
applet.GlobalUnsignedTXInput
applet/Policy.java
applet.Policy
applet/SecretAndTimeStorage.java
applet.SecretAndTimeStorage
applet/GlobalUnsignedTXOutput.java
applet.GlobalUnsignedTXOutput
applet/GlobalMap.java
applet.GlobalMap
applet/PSBT.java
applet.PSBT
applet/MainApplet.java
applet.MainApplet
4 changes: 2 additions & 2 deletions applet/build/tmp/compileTestJava/source-classes-mapping.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/MyUpload.java
tests.MyUpload
tests/TransactionsImported.java
tests.TransactionsImported
tests/AppletTest.java
tests.AppletTest
tests/MyUpload.java
tests.MyUpload
tests/MyTests.java
tests.MyTests
tests/BaseTest.java
Expand Down
3 changes: 1 addition & 2 deletions applet/src/main/java/applet/GlobalMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public void fillUp(short arrayIndex) {
globalUnsignedTX.fill((short) (arrayIndex + mapSize + 2 +
keyPairs[currentKeyPair].value.valueLenBytes));
assert globalUnsignedTX.size == keyPairs[currentKeyPair].value.valueLen;
System.out.print("PSBTv0 parsed" + System.lineSeparator());
}

if (keyPairs[currentKeyPair].key.keyType == PSBT_GLOBAL_INPUT_COUNT) {
Expand All @@ -39,8 +40,6 @@ public void fillUp(short arrayIndex) {

mapSize += keyPairs[currentKeyPair].getSize();
}
//System.out.print("numOfInputMap in fancyKeyPair: " + fancyKeyPairInfo.inputCount + System.lineSeparator());
//System.out.print("numOfOutputMap in fancyKeyPair: " + fancyKeyPairInfo.outputCount + System.lineSeparator());
System.out.print("numOfInputMap: " + numOfInputMaps + System.lineSeparator());
System.out.print("numOfOutputMaps: " + numOfOutputMaps + System.lineSeparator());
}
Expand Down
44 changes: 27 additions & 17 deletions applet/src/main/java/applet/GlobalUnsignedTX.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ public class GlobalUnsignedTX {
short size = 0;

Short inputCount = null;
short currentInput = -1;
GlobalUnsignedTXInput[] inputs = new GlobalUnsignedTXInput[MAX_COUNT_OF_IO];

Short outputCount = null;
short currentOutput = -1;
GlobalUnsignedTXOutput[] outputs = new GlobalUnsignedTXOutput[MAX_COUNT_OF_IO];

Short lockTimeStart = null;
Expand All @@ -35,31 +33,43 @@ public class GlobalUnsignedTX {
public void fill(short arrayIndex){
start = arrayIndex;
version = (short) PSBTdata[start];
inputCount = getInputCount();
size += 4;
inputCount = getCount();
size += byteSizeOfCWI(inputCount);

while (currentInput < inputCount - 1){
currentInput++;
inputs[currentInput].fill((short) (start + size));
size += inputs[currentInput].size;
assert (inputCount) <= MAX_COUNT_OF_IO;

for (short i = 0; i < inputCount; i++) {
inputs[i].fill((short) (start + size));
size += inputs[i].size;
}

outputCount = getOutputCount();
outputCount = getCount();
assert outputCount <= MAX_COUNT_OF_IO;
size += byteSizeOfCWI(outputCount);

while (currentOutput < outputCount - 1){
currentOutput++;
outputs[currentOutput].fill((short)(start + size));
size += outputs[currentOutput].size;
for (short i = 0; i < outputCount; i++) {
outputs[i].fill((short)(start + size));
size += outputs[i].size;
}

}
short getInputCount() {
return compactWeirdoInt((short) (start + 4));
lockTimeStart = size;
size += 4;
print();
}
short getOutputCount() {
short getCount() {
return compactWeirdoInt((short) (start + size));
}

void print(){
System.out.print(("RAW TRANSACTION:" + System.lineSeparator()));
System.out.print("starts at: " + start + System.lineSeparator());
System.out.print("version: " + version + System.lineSeparator());
System.out.print("size: " + size + System.lineSeparator());
System.out.print("input count: " + inputCount + System.lineSeparator());
System.out.print("output count: " + outputCount + System.lineSeparator());
System.out.print("lockTimeStart: " + lockTimeStart + System.lineSeparator());
}

short ignoreInput(short bytesIgnored) {
short signature_scrip_size = compactWeirdoInt((short) (bytesIgnored + 36));
System.out.print("signature_script_size = " + signature_scrip_size + System.lineSeparator());
Expand Down
9 changes: 9 additions & 0 deletions applet/src/main/java/applet/GlobalUnsignedTXInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ void fill(short start){
sequenceStart = (short) (scriptSigStart + scriptSize);
size = (short) (36 + byteSizeOfCWI(scriptSize) + scriptSize + 4); // easier to read and understand this way
}

void print() {
System.out.print("previousOutputStart: " + previousOutputStart + System.lineSeparator());
System.out.print("scriptSizeStart: " + scriptSigStart + System.lineSeparator());
System.out.print("scriptSize: " + scriptSize + System.lineSeparator());
System.out.print("scriptSigStart: " + scriptSigStart + System.lineSeparator());
System.out.print("sequenceStart: " + sequenceStart + System.lineSeparator());
System.out.print("size: " + size + System.lineSeparator());
}
}
8 changes: 8 additions & 0 deletions applet/src/main/java/applet/GlobalUnsignedTXOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ void fill(short start){
scriptPubKeyStart = (short) (scriptSizeStart + byteSizeOfCWI(scriptSize));
size = (short) (8 + byteSizeOfCWI(scriptSize) + scriptSize); // easier to read and understand this way
}

void print(){
System.out.print("valueStart: " + valueStart + System.lineSeparator());
System.out.print("scriptSizeStart: " + scriptSizeStart + System.lineSeparator());
System.out.print("scriptSize: " + scriptSize + System.lineSeparator());
System.out.print("scriptPubKeyStart: " + scriptPubKeyStart + System.lineSeparator());
System.out.print(("size: " + size + System.lineSeparator()));
}
}
3 changes: 0 additions & 3 deletions applet/src/main/java/applet/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ public static short toShort(byte zero, byte first) {
public static short compactWeirdoInt(short intStart) {
assert (PSBTdata[intStart] & 0xff) <= 0xfd;
if ((short) (PSBTdata[intStart] & 0xff) == 0xfd) {
System.out.print("CWI returns " + (Tools.toShort(PSBTdata[intStart + 1],
PSBTdata[intStart + 2])) + System.lineSeparator());
return (Tools.toShort(PSBTdata[intStart + 1], PSBTdata[intStart + 2]));
}
System.out.print("CWI returns " + (short) (PSBTdata[intStart] & 0xff) + System.lineSeparator());
return (short) (PSBTdata[intStart] & 0xff);
}

Expand Down
6 changes: 3 additions & 3 deletions applet/src/test/java/tests/AppletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public void callMyTest() throws Exception {
//myTest.keyPairFillTest();
//myTest.generalFillMapTest();
myTest.sendDataTest(myTest.fromHex(TransactionsImported.validTransaction1));
//myTest.sendDataTest(myTest.fromHex(TransactionsImported.validTransaction2));
//myTest.sendDataTest(myTest.fromHex(TransactionsImported.validTransaction3));
//myTest.sendDataTest(myTest.fromHex(TransactionsImported.validTransaction4));
myTest.sendDataTest(myTest.fromHex(TransactionsImported.validTransaction2));
myTest.sendDataTest(myTest.fromHex(TransactionsImported.validTransaction3));
myTest.sendDataTest(myTest.fromHex(TransactionsImported.validTransaction4));
//myTest.psbtFillTest();
//myTest.psbtFillSimpleTest();
}
Expand Down
2 changes: 1 addition & 1 deletion applet/src/test/java/tests/MyTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class MyTests {

MyUpload test = new MyUpload();

byte[] fromHex(String hex){
static byte[] fromHex(String hex){
// ukradeno
byte[] res = new byte[hex.length() / 2];

Expand Down
44 changes: 41 additions & 3 deletions applet/src/test/java/tests/TransactionsImported.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ public class TransactionsImported {
public static String validTransaction1 = ("70736274ff" + // magic
"0100" + // keylen 1 keytype 0
"75" + // len of value 7 * 16 + 5 bytes
"0200000001268171371edff285e937adeea4b37b78000c0566" +
"cbb3ad64641713ca42171bf60000000000feffffff02d3dff5" +
"02000000" + //version
"01" + // input count
"268171371edff285e937adeea4b37b78000c0566cbb3ad64641713ca42171bf600000000" +
// 36 bytes of previous output hash
"00" + // ??0?? previous output index??
"feff" + // ??previous output index??
"ff" + //script bytesize
"ff02d3dff5" +
"05000000001976a914d0c59903c5bac2868760e90fd521a466" +
"5aa7652088ac00e1f5050000000017a9143545e6e33b832c47" +
"050f24d3eeb93c9c03948bc787b32e1300" + // 117 bytes of value
Expand Down Expand Up @@ -36,7 +42,39 @@ public class TransactionsImported {
"f79a4ea169393380734464f84f2ab300000000000000");


public static String validTransaction2 = ("70736274ff0100a00200000002ab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40000000000feffffffab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40100000000feffffff02603bea0b000000001976a914768a40bbd740cbe81d988e71de2a4d5c71396b1d88ac8e240000000000001976a9146f4620b553fa095e721b9ee0efe9fa039cca459788ac000000000001076a47304402204759661797c01b036b25928948686218347d89864b719e1f7fcf57d1e511658702205309eabf56aa4d8891ffd111fdf1336f3a29da866d7f8486d75546ceedaf93190121035cdc61fc7ba971c0b501a646a2a83b102cb43881217ca682dc86e2d73fa882920001012000e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787010416001485d13537f2e265405a34dbafa9e3dda01fb82308000000");
public static String validTransaction2 = ("70736274ff" +
"0100" + //keylen keytype
"a0" + //length 160
"02000000" + //version 4
"02" + //input count 1
"ab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be400000000" + //36
"00" + // script bytes 1
"feffffff" + //sequence 4
"ab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be401000000" + //36
"00" + // script bytes 1
"feffffff" + //sequence 4
"02" + //output count 1
"603bea0b00000000" + //value 8
"19" + //script size (bytes) 16 + 9 // 1
"76a914768a40bbd740cbe81d988e71de2a4d5c71396b1d88ac" + // 25
"8e24000000000000" + //value 8
"19" + //script size (bytes) 16 + 9 // 1
"76a9146f4620b553fa095e721b9ee0efe9fa039cca459788ac" + // 25
//

"00000000" + // Lock time 4



"00" + // next global map
"01076a47" +
"304402204759661797c01b036b25928948686218347d89864b" +
"719e1f7fcf57d1e511658702205309eabf56aa4d8891ffd111" +
"fdf1336f3a29da866d7f8486d75546ceedaf931901" +
"21035cdc61fc7ba971c0b501a646a2a83b102cb43881217ca682dc86e2d73fa882920001012000e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787010416001485d13537f2e265405a34dbafa9e3dda01fb82308000000");

public static String validTransaction3 = ("70736274ff0100750200000001268171371edff285e937adeea4b37b78000c0566cbb3ad64641713ca42171bf60000000000feffffff02d3dff505000000001976a914d0c59903c5bac2868760e90fd521a4665aa7652088ac00e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787b32e1300000100fda5010100000000010289a3c71eab4d20e0371bbba4cc698fa295c9463afa2e397f8533ccb62f9567e50100000017160014be18d152a9b012039daf3da7de4f53349eecb985ffffffff86f8aa43a71dff1448893a530a7237ef6b4608bbb2dd2d0171e63aec6a4890b40100000017160014fe3e9ef1a745e974d902c4355943abcb34bd5353ffffffff0200c2eb0b000000001976a91485cff1097fd9e008bb34af709c62197b38978a4888ac72fef84e2c00000017a914339725ba21efd62ac753a9bcd067d6c7a6a39d05870247304402202712be22e0270f394f568311dc7ca9a68970b8025fdd3b240229f07f8a5f3a240220018b38d7dcd314e734c9276bd6fb40f673325bc4baa144c800d2f2f02db2765c012103d2e15674941bad4a996372cb87e1856d3652606d98562fe39c5e9e7e413f210502483045022100d12b852d85dcd961d2f5f4ab660654df6eedcc794c0c33ce5cc309ffb5fce58d022067338a8e0e1725c197fb1a88af59f51e44e4255b20167c8684031c05d1f2592a01210223b72beef0965d10be0778efecd61fcac6f79a4ea169393380734464f84f2ab30000000001030401000000000000");
public static String validTransaction4 = "70736274ff0100a00200000002ab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40000000000feffffffab0949a08c5af7c49b8212f417e2f15ab3f5c33dcf153821a8139f877a5b7be40100000000feffffff02603bea0b000000001976a914768a40bbd740cbe81d988e71de2a4d5c71396b1d88ac8e240000000000001976a9146f4620b553fa095e721b9ee0efe9fa039cca459788ac00000000000100df0200000001268171371edff285e937adeea4b37b78000c0566cbb3ad64641713ca42171bf6000000006a473044022070b2245123e6bf474d60c5b50c043d4c691a5d2435f09a34a7662a9dc251790a022001329ca9dacf280bdf30740ec0390422422c81cb45839457aeb76fc12edd95b3012102657d118d3357b8e0f4c2cd46db7b39f6d9c38d9a70abcb9b2de5dc8dbfe4ce31feffffff02d3dff505000000001976a914d0c59903c5bac2868760e90fd521a4665aa7652088ac00e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787b32e13000001012000e1f5050000000017a9143545e6e33b832c47050f24d3eeb93c9c03948bc787010416001485d13537f2e265405a34dbafa9e3dda01fb8230800220202ead596687ca806043edc3de116cdf29d5e9257c196cd055cf698c8d02bf24e9910b4a6ba670000008000000080020000800022020394f62be9df19952c5587768aeb7698061ad2c4a25c894f47d8c162b4d7213d0510b4a6ba6700000080010000800200008000";

public static String givenRaw = "0100000001f3f6a909f8521adb57d898d2985834e632374e770fd9e2b98656f1bf1fdfd427010000006b48304502203a776322ebf8eb8b58cc6ced4f2574f4c73aa664edce0b0022690f2f6f47c521022100b82353305988cb0ebd443089a173ceec93fe4dbfe98d74419ecc84a6a698e31d012103c5c1bc61f60ce3d6223a63cedbece03b12ef9f0068f2f3c4a7e7f06c523c3664ffffffff0260e31600000000001976a914977ae6e32349b99b72196cb62b5ef37329ed81b488ac063d1000000000001976a914f76bc4190f3d8e2315e5c11c59cfc8be9df747e388ac00000000";
}

0 comments on commit 6414362

Please sign in to comment.