mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +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() {
|
public String toDisplayString() {
|
||||||
|
return toDisplayString(chunks);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String toDisplayString(List<ScriptChunk> scriptChunks) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
int signatureCount = 1;
|
int signatureCount = 1;
|
||||||
int pubKeyCount = 1;
|
int pubKeyCount = 1;
|
||||||
for(ScriptChunk chunk : chunks) {
|
for(ScriptChunk chunk : scriptChunks) {
|
||||||
if(chunk.isSignature()) {
|
if(chunk.isSignature()) {
|
||||||
builder.append("<signature").append(signatureCount++).append(">");
|
builder.append("<signature").append(signatureCount++).append(">");
|
||||||
} else if(chunk.isScript()) {
|
} else if(chunk.isScript()) {
|
||||||
|
|
|
@ -145,6 +145,16 @@ public class ScriptChunk {
|
||||||
return opcodeLength + pushDataSizeLength + dataLength;
|
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() {
|
public String toString() {
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return "OP_" + getOpCodeName(opcode);
|
return "OP_" + getOpCodeName(opcode);
|
||||||
|
|
|
@ -56,19 +56,28 @@ public class TransactionWitness {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (byte[] push : pushes) {
|
for (byte[] push : pushes) {
|
||||||
if (push == null) {
|
if (push == null) {
|
||||||
buffer.append("NULL");
|
builder.append("NULL");
|
||||||
} else if (push.length == 0) {
|
} else if (push.length == 0) {
|
||||||
buffer.append("EMPTY");
|
builder.append("EMPTY");
|
||||||
} else {
|
} 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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue