mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
witness as display string
This commit is contained in:
parent
e574a2bfd3
commit
4d875f5ad0
3 changed files with 30 additions and 7 deletions
|
@ -246,10 +246,14 @@ public class Script {
|
|||
}
|
||||
|
||||
public String toDisplayString() {
|
||||
return toDisplayString(chunks);
|
||||
}
|
||||
|
||||
static String toDisplayString(List<ScriptChunk> scriptChunks) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int signatureCount = 1;
|
||||
int pubKeyCount = 1;
|
||||
for(ScriptChunk chunk : chunks) {
|
||||
for(ScriptChunk chunk : scriptChunks) {
|
||||
if(chunk.isSignature()) {
|
||||
builder.append("<signature").append(signatureCount++).append(">");
|
||||
} else if(chunk.isScript()) {
|
||||
|
|
|
@ -145,6 +145,16 @@ public class ScriptChunk {
|
|||
return opcodeLength + pushDataSizeLength + dataLength;
|
||||
}
|
||||
|
||||
static int getOpcodeForLength(int length) {
|
||||
if(length <= 0xFF) {
|
||||
return OP_PUSHDATA1;
|
||||
}
|
||||
if(length <= 0xFFFF) {
|
||||
return OP_PUSHDATA2;
|
||||
}
|
||||
return OP_PUSHDATA4;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (data == null) {
|
||||
return "OP_" + getOpCodeName(opcode);
|
||||
|
|
|
@ -56,19 +56,28 @@ public class TransactionWitness {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (byte[] push : pushes) {
|
||||
if (push == null) {
|
||||
buffer.append("NULL");
|
||||
builder.append("NULL");
|
||||
} else if (push.length == 0) {
|
||||
buffer.append("EMPTY");
|
||||
builder.append("EMPTY");
|
||||
} else {
|
||||
buffer.append(Hex.toHexString(push));
|
||||
builder.append(Hex.toHexString(push));
|
||||
}
|
||||
buffer.append(" ");
|
||||
builder.append(" ");
|
||||
}
|
||||
|
||||
return buffer.toString().trim();
|
||||
return builder.toString().trim();
|
||||
}
|
||||
|
||||
public String toDisplayString() {
|
||||
List<ScriptChunk> scriptChunks = new ArrayList<>(pushes.size());
|
||||
for(byte[] push : pushes) {
|
||||
scriptChunks.add(new ScriptChunk(ScriptChunk.getOpcodeForLength(push.length), push));
|
||||
}
|
||||
|
||||
return Script.toDisplayString(scriptChunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue