Language

Choose a language

/build/rpc / contracts / forward

forward.build_coop_close

  • workflowforward-lifecycle·step 7 of 10Workflow: forward-lifecycle · step 7 of 10

forward.build_coop_close "id" ( {"to_long":[{"asset_id":"hex","amount":n,"address":"str"},...],"to_short":[{"asset_id":"hex","amount":n,"address":"str"},...]} {"long_vault_txid":"hex","long_vault_vout":n,"short_vault_txid":"hex","short_vault_vout":n,"locktime":n} ) Construct a cooperative close PSBT for a forward contract. Both parties must agree on the settlement terms and sign. This spends both IM vaults and distributes assets according to the agreed settlement. Arguments: 1. id (string, required) Forward contract identifier 2. settlement (json object, optional) Settlement distribution (defaults to cooperative leaf layout) { "to_long": [ (json array, required) Outputs to long party { (json object, required) "asset_id": "hex", (string, optional) Asset ID (omit for native BTC) "amount": n, (numeric, required) Amount in sats or asset units "address": "str", (string, optional) Destination (defaults to long party's settlement address) }, ... ], "to_short": [ (json array, required) Outputs to short party { (json object, required) "asset_id": "hex", (string, optional) Asset ID (omit for native BTC) "amount": n, (numeric, required) Amount in sats or asset units "address": "str", (string, optional) Destination (defaults to short party's settlement address) }, ... ], } 3. options (json object, optional) Optional builder settings { "long_vault_txid": "hex", (string, optional) Override long vault outpoint txid "long_vault_vout": n, (numeric, optional) Override long vault outpoint index "short_vault_txid": "hex", (string, optional) Override short vault outpoint txid "short_vault_vout": n, (numeric, optional) Override short vault outpoint index "locktime": n, (numeric, optional) Override transaction nLockTime } Result: { (json object) "psbt" : "str", (string) Base64-encoded PSBT "fee" : n, (numeric) Estimated fee (in BTC) "changepos" : n, (numeric) Index of wallet-generated change output (-1 if none) "complete" : true|false, (boolean) Whether the PSBT contains all signatures "roll_terms" : { (json object, optional) Suggested forward terms to roll the position ... } } Examples: > bitcoin-cli forward.build_coop_close "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "{\"to_long\":[...], \"to_short\":[...]}"

Signature

forward.build_coop_close(id: string, settlement?: object, options?: object) → any

Code samples

curl --user "$RPC_USER:$RPC_PASS" \
  --data-binary '{"jsonrpc":"1.0","id":"docs","method":"forward.build_coop_close","params":["\"<id>\"",{},{}]}' \
  -H 'content-type: text/plain;' \
  http://127.0.0.1:8332/

Parameters

NameTypeReq.Description
idstringyesForward contract identifier
settlementobjectSettlement distribution (defaults to cooperative leaf layout) { "to_long": [ (json array, required) Outputs to long party { (json object, required) "asset_id": "hex", (string, optional) Asset ID (omit for native BTC) "amount": n, (numeric, required) Amount in sats or asset units "address": "str", (string, optional) Destination (defaults to long party's settlement address) }, ... ], "to_short": [ (json array, required) Outputs to short party { (json object, required) "asset_id": "hex", (string, optional) Asset ID (omit for native BTC) "amount": n, (numeric, required) Amount in sats or asset units "address": "str", (string, optional) Destination (defaults to short party's settlement address) }, ... ], }
optionsobjectOptional builder settings { "long_vault_txid": "hex", (string, optional) Override long vault outpoint txid "long_vault_vout": n, (numeric, optional) Override long vault outpoint index "short_vault_txid": "hex", (string, optional) Override short vault outpoint txid "short_vault_vout": n, (numeric, optional) Override short vault outpoint index "locktime": n, (numeric, optional) Override transaction nLockTime }

Result

Type:  any

{ (json object) "psbt" : "str", (string) Base64-encoded PSBT "fee" : n, (numeric) Estimated fee (in BTC) "changepos" : n, (numeric) Index of wallet-generated change output (-1 if none) "complete" : true|false, (boolean) Whether the PSBT contains all signatures "roll_terms" : { (json object, optional) Suggested forward terms to roll the position ... } }

Source: services/core-node/bcore/src/wallet/rpc/contracts.cpp:16193

C++ symbol: forward_build_coop_close