Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix qx encode and sign #264

Merged
merged 10 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions cmd/qx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,27 @@ addr & tx & sign
msg-verify validate a message signature
signature-decode decode a ECDSA signature
```

### Qx Support UnLock script Types
- `pubkeyhash` the txid vout address need pubkeyhash address
- `pubkey` the txid vout address need pubkey address
- `cltvpubkeyhash` the txid vout address need pubkeyhash address, sequence need 4294967294 and need lock a height or time
- `crossimport` the special script, the index need 4294967294 and sequence need 258

### Qx Support Lock script Types
- `pubkeyhash` the txid vout address need pubkeyhash address
- `pubkey` the txid vout address need pubkey address
- `cltvpubkeyhash` the txid vout address need pubkeyhash address, and need lock a height or time

## Examples

### TxTypeRegular (Regular MEER Tx)
From UTXO: ```5fdad6bb6781416b0361a10eb6183dec45fb31edcf2da10d22893ee7bb6502ca``` to MEER ```XmRTajVTajFiaEkd7PygFw46vNsoNW6fWE5``` 9.9999 MEER coinID : 0 MEER
```bash
$ ./qx tx-encode -v 1 -i 5fdad6bb6781416b0361a10eb6183dec45fb31edcf2da10d22893ee7bb6502ca:0:4294967295:TxTypeRegular -l 0 -o XmRTajVTajFiaEkd7PygFw46vNsoNW6fWE5:9.9999:0:TxTypeRegular
$ ./qx tx-encode -v 1 -i 5fdad6bb6781416b0361a10eb6183dec45fb31edcf2da10d22893ee7bb6502ca:0:4294967295:pubkeyhash -l 0 -o XmRTajVTajFiaEkd7PygFw46vNsoNW6fWE5:9.9999:0:pubkeyhash
```
```output
0100000001ca0265bbe73e89220da12dcfed31fb45ec3d18b60ea161036b418167bbd6da5f00000000ffffffff010000f0a29a3b000000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac000000000000000004b3c3620100-7b22696e707574223a7b2230223a307d2c226f7574707574223a7b2230223a307d7d
0100000001ca0265bbe73e89220da12dcfed31fb45ec3d18b60ea161036b418167bbd6da5f00000000ffffffff010000f0a29a3b000000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac0000000000000000faac64630100-7b22696e707574223a7b2230223a327d2c226f7574707574223a7b2230223a327d7d
```
```bash
$ ./qx tx-decode 0100000001ca0265bbe73e89220da12dcfed31fb45ec3d18b60ea161036b418167bbd6da5f00000000ffffffff010000f0a29a3b000000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac000000000000000004b3c3620100-7b22696e707574223a7b2230223a307d2c226f7574707574223a7b2230223a307d7d
Expand All @@ -91,7 +104,7 @@ $ ./qx tx-decode 0100000001ca0265bbe73e89220da12dcfed31fb45ec3d18b60ea161036b418
"locktime": 0,
"expire": 0,
"vin": [{
"type": "TxTypeRegular",
"type": "pubkeyhash",
"scriptSig": {
"asm": "",
"hex": ""
Expand Down Expand Up @@ -153,7 +166,7 @@ $ ./qx sign -k (privateKey) -n mixnet 0100000001ca0265bbe73e89220da12dcfed31fb45
From UTXO: ```5fdad6bb6781416b0361a10eb6183dec45fb31edcf2da10d22893ee7bb6502ca``` to MEER PKAddress ```XkCfdHoHHe2raZwNoY4sKcXFf6Jy9Q8XotAHenYsucPrEoj1FeUTR``` 9.9999 MEER coinID : 1 ETH

```bash
$ ./qx tx-encode -v 1 -i 5fdad6bb6781416b0361a10eb6183dec45fb31edcf2da10d22893ee7bb6502ca:0:4294967295:TxTypeCrossChainExport -l 0 -o XkCfdHoHHe2raZwNoY4sKcXFf6Jy9Q8XotAHenYsucPrEoj1FeUTR:9.9999:1:TxTypeCrossChainExport
$ ./qx tx-encode -v 1 -i 5fdad6bb6781416b0361a10eb6183dec45fb31edcf2da10d22893ee7bb6502ca:0:4294967295:pubkey -l 0 -o XkCfdHoHHe2raZwNoY4sKcXFf6Jy9Q8XotAHenYsucPrEoj1FeUTR:9.9999:1:pubkey
```
```output
0100000001ca0265bbe73e89220da12dcfed31fb45ec3d18b60ea161036b418167bbd6da5f00000000ffffffff010100f0a29a3b000000002321039d05472a845abf3cf5548567ee968d3ef3cd0f064fdb1bd2b6b791ab28f681ffac00000000000000000ca4c3620100-7b22696e707574223a7b2230223a3235377d2c226f7574707574223a7b2230223a3235377d7d
Expand All @@ -169,7 +182,7 @@ $ ./qx tx-decode 0100000001ca0265bbe73e89220da12dcfed31fb45ec3d18b60ea161036b418
"locktime": 0,
"expire": 0,
"vin": [{
"type": "TxTypeCrossChainExport",
"type": "pubkey",
"scriptSig": {
"asm": "",
"hex": ""
Expand Down Expand Up @@ -232,13 +245,13 @@ $ ./qx tx-decode 0100000001ca0265bbe73e89220da12dcfed31fb45ec3d18b60ea161036b418
### TxTypeCrossChainImport (TX from EVM to MEER)
From EVM to MEER PKAddress ```XkCfdHoHHe2raZwNoY4sKcXFf6Jy9Q8XotAHenYsucPrEoj1FeUTR``` 100 MEER coinID : 0 MEER
```bash
$ ./qx tx-encode -v 1 -i 0000000000000000000000000000000000000000000000000000000000000000:4294967294:258:TxTypeCrossChainImport -l 0 -o XkCfdHoHHe2raZwNoY4sKcXFf6Jy9Q8XotAHenYsucPrEoj1FeUTR:100:0:TxTypeCrossChainImport
$ ./qx tx-encode -v 1 -i 0000000000000000000000000000000000000000000000000000000000000000:4294967294:258:crossimport -l 0 -o XmRTajVTajFiaEkd7PygFw46vNsoNW6fWE5:100:0:pubkeyhash
```
```output
01000000010000000000000000000000000000000000000000000000000000000000000000feffffff0201000001000000e40b54020000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac0000000000000000cba5c3620100-7b22696e707574223a7b2230223a3235387d2c226f7574707574223a7b2230223a3235387d7d
01000000010000000000000000000000000000000000000000000000000000000000000000feffffff0201000001000000e40b54020000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac000000000000000033ae64630100-7b22696e707574223a7b2230223a3235357d2c226f7574707574223a7b2230223a307d7d
```
```bash
./qx tx-encode 01000000010000000000000000000000000000000000000000000000000000000000000000feffffff0201000001000000e40b54020000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac0000000000000000cba5c3620100-7b22696e707574223a7b2230223a3235387d2c226f7574707574223a7b2230223a3235387d7d
./qx tx-encode 01000000010000000000000000000000000000000000000000000000000000000000000000feffffff0201000001000000e40b54020000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac000000000000000033ae64630100-7b22696e707574223a7b2230223a3235357d2c226f7574707574223a7b2230223a307d7d
```
```json
{
Expand All @@ -248,7 +261,7 @@ $ ./qx tx-encode -v 1 -i 0000000000000000000000000000000000000000000000000000000
"locktime": 0,
"expire": 0,
"vin": [{
"type": "TxTypeCrossChainImport",
"type": "crossimport",
"scriptSig": null
}],
"vout": [{
Expand All @@ -259,13 +272,13 @@ $ ./qx tx-encode -v 1 -i 0000000000000000000000000000000000000000000000000000000
"hex": "76a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": ["MmbRPt1wRcHz1mAiH8Ri1ANtGRyY5ygJ3hJ"]
"addresses": ["XmRTajVTajFiaEkd7PygFw46vNsoNW6fWE5"]
}
}]
}
```
```bash
$ ./qx sign -k (privateKey) -n mixnet 01000000010000000000000000000000000000000000000000000000000000000000000000feffffff0201000001000000e40b54020000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac0000000000000000cba5c3620100-7b22696e707574223a7b2230223a3235387d2c226f7574707574223a7b2230223a3235387d7d
$ ./qx sign -k (privateKey) -n mixnet 01000000010000000000000000000000000000000000000000000000000000000000000000feffffff0201000001000000e40b54020000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac000000000000000033ae64630100-7b22696e707574223a7b2230223a3235357d2c226f7574707574223a7b2230223a307d7d
```
```output
01000000010000000000000000000000000000000000000000000000000000000000000000feffffff0201000001000000e40b54020000001976a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac0000000000000000cba5c3620180354d6b42384655315135444761556e7753733679446a36364a7747654550394b4c5461786b626d5351684e396e546d70336566356a6b49483045022100ec14a41b314afc8c4348bab9122176f8d6b4ccbcaf4be1d2dc9be539cf89d98202203eb78a38c0403a8a8bcb63a30f4f39e1bd05031f55bd4c31a902567a5d6f155601
Expand All @@ -281,7 +294,7 @@ $ ./qx tx-decode 010000000100000000000000000000000000000000000000000000000000000
"locktime": 0,
"expire": 0,
"vin": [{
"type": "TxTypeCrossChainImport",
"type": "crossimport",
"scriptSig": null
}],
"vout": [{
Expand All @@ -292,7 +305,7 @@ $ ./qx tx-decode 010000000100000000000000000000000000000000000000000000000000000
"hex": "76a914ada117669b04771e481cc68ae8d4f33f913d1eda88ac",
"reqSigs": 1,
"type": "pubkeyhash",
"addresses": ["MmbRPt1wRcHz1mAiH8Ri1ANtGRyY5ygJ3hJ"]
"addresses": ["XmRTajVTajFiaEkd7PygFw46vNsoNW6fWE5"]
}
}]
}
Expand Down
36 changes: 23 additions & 13 deletions cmd/qx/qx.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var txInputs qx.TxInputsFlag
var txOutputs qx.TxOutputsFlag
var txVersion qx.TxVersionFlag
var txLockTime qx.TxLockTimeFlag
var privateKey string
var privateKeys qx.TxPrivateKey
var msgSignatureMode string

func main() {
Expand Down Expand Up @@ -428,25 +428,35 @@ func main() {
txVersion = qx.TxVersionFlag(TX_VERION) //set default tx version
txEncodeCmd.Var(&txVersion, "v", "the transaction version")
txEncodeCmd.Var(&txLockTime, "l", "the transaction lock time")
txEncodeCmd.Var(&txInputs, "i", `The set of transaction input points encoded as TXHASH:INDEX:SEQUENCE:TXTYPE.
txEncodeCmd.Var(&txInputs, "i", `The set of transaction input points encoded as TXHASH:INDEX:SEQUENCE:SCRIPTTYPE:[args].
-i 5fdad6bb6781416b0361a10eb6183dec45fb31edcf2da10d22893ee7bb6502ca:0:4294967295:pubkeyhash
TXHASH is a Base16 transaction hash. INDEX is the 32 bit input index
in the context of the transaction. SEQUENCE is the optional 32 bit
input sequence and defaults to the maximum value.
TXTYPE is type type
TxTypeRegular the standard tx
TxTypeGenesisLock the tx try to lock the genesis output to the stake pool
TxTypeCrossChainExport Cross chain by import tx
TxTypeCrossChainImport Cross chain by vm tx
UNLOCKTYPE is unlock script type
- pubkeyhash PayToAddrScript(pkh)
- pubkey PayToAddrScript(pk)
- cltvpubkeyhash Sequence is the locktime or lockheight PayToCLTVPubKeyHashScript(pkh, args) TXHASH:INDEX:SEQUENCE:SCRIPTTYPE:locktime.
- crossimport the special script, the index need 4294967294 and sequence need 258
`)
txEncodeCmd.Var(&txOutputs, "o", `The set of transaction output data encoded as ADDRESS:AMOUNT:COINID:SCRIPTTYPE:[ARGS].
-o XmRTajVTajFiaEkd7PygFw46vNsoNW6fWE5:9.9999:0:pubkeyhash
-o XmRTajVTajFiaEkd7PygFw46vNsoNW6fWE5:9.9999:0:cltvpubkeyhash:1667298670

ADDRESS is an address (pay-to-pubkey-hash or pay-to-script-hash).
AMOUNT is the 64 bit spend amount in qitmeer.
COINID enum {0 => MEER,1=>ETHID}
LOCKTYPE is lock script type
- pubkeyhash PayToAddrScript(pkh)
- pubkey PayToAddrScript(pk)
- cltvpubkeyhash ADDRESS:AMOUNT:COINID:SCRIPTTYPE:LOCKTIME PayToCLTVPubKeyHashScript(pkh, LOCKTIME))
`)
txEncodeCmd.Var(&txOutputs, "o", `The set of transaction output data encoded as TARGET:MEER:COINID:TXTYPE.
TARGET is an address (pay-to-pubkey-hash or pay-to-script-hash).
MEER is the 64 bit spend amount in qitmeer.COINID enum {0 => MEER,1=>ETHID}`)

txSignCmd := flag.NewFlagSet("tx-sign", flag.ExitOnError)
txSignCmd.Usage = func() {
cmdUsage(txSignCmd, "Usage: qx tx-sign [raw_tx_base16_string] \n")
}
txSignCmd.StringVar(&privateKey, "k", "", "the ec private key to sign the raw transaction")
txSignCmd.Var(&privateKeys, "k", "the ec private key to sign the raw transaction")
txSignCmd.StringVar(&network, "n", "mainnet", "decode rawtx for the target network. (mainnet, testnet, privnet)")

msgSignCmd := flag.NewFlagSet("msg-sign", flag.ExitOnError)
Expand Down Expand Up @@ -1416,15 +1426,15 @@ MEER is the 64 bit spend amount in qitmeer.COINID enum {0 => MEER,1=>ETHID}`)
if len(os.Args) == 2 || os.Args[2] == "help" || os.Args[2] == "--help" {
txSignCmd.Usage()
} else {
qx.TxSignSTDO(privateKey, os.Args[len(os.Args)-1], network)
qx.TxSignSTDO(privateKeys, os.Args[len(os.Args)-1], network)
}
} else { //try from STDIN
src, err := ioutil.ReadAll(os.Stdin)
if err != nil {
errExit(err)
}
str := strings.TrimSpace(string(src))
qx.TxSignSTDO(privateKey, str, network)
qx.TxSignSTDO(privateKeys, str, network)
}
}

Expand Down
Loading