Destination

As with the source, there are two types of destinations: single or multiple.

Single destination

The most basic format. The amount is deducted from the available balance (available.balance) of a single source and transferred to a single destination (distribute).

Multi-destination

With multiple destinations, you will have the amount credited to different destinations. For example, 38% of the total amount will be sent to Account A, 50% to Account B, and the rest will be sent to Account C.

  • If the total percentage in distribute exceeds 100%, an error will be returned. If any remaining percentage is not used, a message will be returned indicating such.

Code examples

(transaction v1
  (chart-of-accounts-group-name PAG_CONTAS_CODE_123182371973821973981)
  (metadata
      (anyKey anyValue)
      (anotherKey anotherValue)
  )
  (description "description for the transaction not for the operation")
  (send BRL 30|4 
    (source
      (from@external/BRL
        (description "description shown on the statement")
      )
  )
 )
  (distribute
    (to 540b504c-8f9d-480f-9354-3728cf7025ef :share 100
      (metadata
		(label myText)
		(operationKey operationValue)
      )
    )
  )
)

Multi-source and multi-destination

An example of a multi-source, multi-destination transaction would be a fundraiser aimed at distributing money to several families affected by a flood. In the example below, a transaction of BRL 0.0030 is sent, with the amount coming from various sources and going to different destinations, according to specific weights (previously explained).

Code example

(transaction v1
  (chart-of-accounts-group-name PAG_CONTAS_CODE_123182371973821973981)
  (metadata
    (anyKey anyValue)
    (anotherKey anotherValue)
  )
  (description "description for the transaction not for the operation")
  (send BRL 30|4
    (source
      (from 3172933b-50d2-4b17-96aa-9b378d6a6eac :share 90 :of 25
        (description "Whatever")
        (metadata
          (label myText)
          (operationKey operationValue)
        )
      )
      (from aacb6967-d201-43d5-beb0-db7ac0f6f5a3 :share 5 :of 25)
      (from 62a3fd1d-0f54-4544-aeaa-dd45e306ade4 :share 5 :of 25)
      (from 8a1b173c-35fc-41f4-ac94-6b202e0bcd7f :share 12)
      (from dd76761b-68e1-49f7-adcc-6788dd1a3656 :amount BRL 2|4)
      (from 01de90bf-5d09-461e-8a24-8e5cdb94968e :remaining)
    )
  )
  (distribute
    (to 540b504c-8f9d-480f-9354-3728cf7025ef :share 38)
    (to 1a9ba2dd-d778-415f-a61a-387d64994eeb :share 50
      (description "hello world")
    )
    (to 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :amount BRL 2|4)
    (distribute :remaining
      (to 54748fc9-53f1-4d5b-bdc3-660c64f1e974 :share 2)
      (to 9fe618ed-cec1-4a5b-90d8-2f5819a8c3dd :remaining)
    )
  )
)

We are not working with percentage points. Therefore, in the example above, :share 5 of 25 translates to 5% of 25%, which is 0.05 * 0.25 = 0.0125, or 1.25%.

Last updated