Submit cancellation
post
Body
all ofOptional
Represents the cancellation transaction request to/from REST.
This type is used to decode the cancellation request from REST.
Responses
200Success
application/json
400
Client error
application/json
404
Resource not found
application/json
408
Request timeout
application/json
422
Business logic error
application/json
500
Internal server error
application/json
post
POST /v1/transactions/cancellation HTTP/1.1
Host: api.testnet.1money.network
Content-Type: application/json
Accept: */*
Content-Length: 214
{
"chain_id": 1,
"nonce": 1,
"signature": {
"r": "72956732934625920503481762689501378577921804342307439094906376029324416116949",
"s": "29902520081700531224291681396692026253288382272435451874524203378285409371412",
"v": "1"
}
}
{
"hash": "0xf55f9525be94633b56f954d3252d52b8ef42f5fd5f9491b243708471c15cc40c"
}
The following code segment demonstrates a Golang implementation for transaction cancellation.
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"math/big"
)
var privateKey = "01833a126ec45d0191519748146b9e35647aab7fed28de1c8e17824970f964a3"
type CancellationMessage struct {
ChainID *big.Int
Nonce uint64
}
type Signature struct {
R string
S string
V uint64
}
func SignMessage(msg *CancellationMessage) (*Signature, error) {
encoded, err := rlp.EncodeToBytes(msg)
if err != nil {
return nil, err
}
hash := crypto.Keccak256(encoded)
fmt.Printf("Signature Hash: %s\n", common.BytesToHash(hash))
key, err := crypto.HexToECDSA(privateKey)
if err != nil {
return nil, err
}
sign, err := crypto.Sign(hash, key)
if err != nil {
return nil, err
}
fmt.Printf("Signature: 0x%x\n", sign)
fmt.Printf("Raw bytes: %v\n", sign)
r := sign[:32]
s := sign[32:64]
v := sign[64]
return &Signature{
R: common.BytesToHash(r).Hex(),
S: common.BytesToHash(s).Hex(),
V: uint64(v),
}, nil
}
func main() {
cancel := &CancellationMessage{
ChainID: big.NewInt(1212101),
Nonce: 0,
}
signature, err := SignMessage(cancel)
if err != nil {
panic(fmt.Sprintf("sign cancel msg error: %v", err))
}
fmt.Printf("Cancellation msg Signature: %v\n", signature)
}
Last updated