UDTswap_scripts/UDTswap_udt_based.c
int check_liquidity_udt_script(size_t index, size_t source) {
  uint8_t script_buf[UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE];
  uint8_t *script_code_hash_buf;
  uint8_t *script_args_lock_hash_buf;
  uint8_t *script_args_tx_input_buf;
  uint64_t len = UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE;
  int ret = ckb_load_cell_by_field(script_buf, &len, 0, index, source, CKB_CELL_FIELD_TYPE);
  if(ret != CKB_SUCCESS) {
    return UDTSWAP_SYSCALL_ERROR - ret;
  }
  if(len != UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE) {
    return UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE_NOT_CORRECT_ERROR;
  }

  script_code_hash_buf = &script_buf[CODE_HASH_START];
  script_args_lock_hash_buf = &script_buf[ARGS_START];
  script_args_tx_input_buf = &script_buf[UDTSWAP_LIQUIDITY_UDT_ARGS_TX_INPUT_START];

  if(memcmp(udtswap_liquidity_udt_code_hash_buf, script_code_hash_buf, CODE_HASH_SIZE) != 0) {
    return CODE_HASH_NOT_MATCH_ERROR;
  }
  //udtswap liquidity udt code hash checked

  uint8_t script_buf2[UDTSWAP_TYPE_SCRIPT_SIZE];
  uint8_t *script_args_tx_input_buf2;
  len = UDTSWAP_TYPE_SCRIPT_SIZE;
  ret = ckb_load_cell_by_field(script_buf2, &len, 0, UDTSWAP_TYPE_CELL_INDEX, CKB_SOURCE_INPUT, CKB_CELL_FIELD_TYPE);
  if(ret != CKB_SUCCESS) {
    return UDTSWAP_SYSCALL_ERROR - ret;
  }
  if(len != UDTSWAP_TYPE_SCRIPT_SIZE) {
    return UDTSWAP_TYPE_SCRIPT_SIZE_NOT_CORRECT_ERROR;
  }

  script_args_tx_input_buf2 = &script_buf2[ARGS_START];

  if(memcmp(script_args_tx_input_buf, script_args_tx_input_buf2, TX_INPUT_SIZE) != 0) {
    return TX_INPUT_NOT_MATCH_ERROR;
  }
  //udtswap tx input and udtswap liquidity udt tx input same checked

  uint8_t script_hash_buf[SCRIPT_HASH_SIZE];
  len = SCRIPT_HASH_SIZE;
  ret = ckb_load_cell_by_field(script_hash_buf, &len, 0, UDTSWAP_TYPE_CELL_INDEX, CKB_SOURCE_INPUT, CKB_CELL_FIELD_LOCK_HASH);
  if(ret != CKB_SUCCESS) {
    return UDTSWAP_SYSCALL_ERROR - ret;
  }
  if(len != SCRIPT_HASH_SIZE) {
    return SCRIPT_HASH_SIZE_NOT_CORRECT_ERROR;
  }

  if(memcmp(script_hash_buf, script_args_lock_hash_buf, SCRIPT_HASH_SIZE) != 0) {
    return SCRIPT_NOT_MATCH_ERROR;
  }
  //udtswap lock hash and udtswap liquidity owner lock same checked

  return CKB_SUCCESS;
}
/*
 * @dev check UDTswap liquidity udt script
 * check tx input
 * check lock script hash (owner mode)
 *
 * @param index UDTswap liquidity udt cell index
 * @param source UDTswap liquidity udt cell source
 */
@dev check UDTswap liquidity udt script
check tx input
check lock script hash (owner mode)

@param index UDTswap liquidity udt cell index
@param source UDTswap liquidity udt cell source
@dev check UDTswap liquidity udt script check tx input check lock script hash ( owner mode ) @param index UDTswap liquidity udt cell index @param source UDTswap liquidity udt cell source
int check_liquidity_udt_script(size_t index, size_t source) {
  uint8_t script_buf[UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE];
  uint8_t *script_code_hash_buf;
  uint8_t *script_args_lock_hash_buf;
  uint8_t *script_args_tx_input_buf;
  uint64_t len = UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE;
  int ret = ckb_load_cell_by_field(script_buf, &len, 0, index, source, CKB_CELL_FIELD_TYPE);
  if(ret != CKB_SUCCESS) {
    return UDTSWAP_SYSCALL_ERROR - ret;
  }
  if(len != UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE) {
    return UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE_NOT_CORRECT_ERROR;
  }
  script_code_hash_buf = &script_buf[CODE_HASH_START];
  script_args_lock_hash_buf = &script_buf[ARGS_START];
  script_args_tx_input_buf = &script_buf[UDTSWAP_LIQUIDITY_UDT_ARGS_TX_INPUT_START];
  if(memcmp(udtswap_liquidity_udt_code_hash_buf, script_code_hash_buf, CODE_HASH_SIZE) != 0) {
    return CODE_HASH_NOT_MATCH_ERROR;
  }
  uint8_t script_buf2[UDTSWAP_TYPE_SCRIPT_SIZE];
  uint8_t *script_args_tx_input_buf2;
  len = UDTSWAP_TYPE_SCRIPT_SIZE;
  ret = ckb_load_cell_by_field(script_buf2, &len, 0, UDTSWAP_TYPE_CELL_INDEX, CKB_SOURCE_INPUT, CKB_CELL_FIELD_TYPE);
  if(ret != CKB_SUCCESS) {
    return UDTSWAP_SYSCALL_ERROR - ret;
  }
  if(len != UDTSWAP_TYPE_SCRIPT_SIZE) {
    return UDTSWAP_TYPE_SCRIPT_SIZE_NOT_CORRECT_ERROR;
  }
  script_args_tx_input_buf2 = &script_buf2[ARGS_START];
  if(memcmp(script_args_tx_input_buf, script_args_tx_input_buf2, TX_INPUT_SIZE) != 0) {
    return TX_INPUT_NOT_MATCH_ERROR;
  }
  uint8_t script_hash_buf[SCRIPT_HASH_SIZE];
  len = SCRIPT_HASH_SIZE;
  ret = ckb_load_cell_by_field(script_hash_buf, &len, 0, UDTSWAP_TYPE_CELL_INDEX, CKB_SOURCE_INPUT, CKB_CELL_FIELD_LOCK_HASH);
  if(ret != CKB_SUCCESS) {
    return UDTSWAP_SYSCALL_ERROR - ret;
  }
  if(len != SCRIPT_HASH_SIZE) {
    return SCRIPT_HASH_SIZE_NOT_CORRECT_ERROR;
  }
  if(memcmp(script_hash_buf, script_args_lock_hash_buf, SCRIPT_HASH_SIZE) != 0) {
    return SCRIPT_NOT_MATCH_ERROR;
  }
  return CKB_SUCCESS;
}
int check_liquidity_udt_script ( size_t index , size_t source ) { uint8_t script_buf [ UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE ] ; uint8_t * script_code_hash_buf ; uint8_t * script_args_lock_hash_buf ; uint8_t * script_args_tx_input_buf ; uint64_t len = UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE ; int ret = ckb_load_cell_by_field ( script_buf , & len , 0 , index , source , CKB_CELL_FIELD_TYPE ) ; if ( ret != CKB_SUCCESS ) { return UDTSWAP_SYSCALL_ERROR - ret ; } if ( len != UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE ) { return UDTSWAP_LIQUIDITY_UDT_TYPE_SCRIPT_SIZE_NOT_CORRECT_ERROR ; } script_code_hash_buf = & script_buf [ CODE_HASH_START ] ; script_args_lock_hash_buf = & script_buf [ ARGS_START ] ; script_args_tx_input_buf = & script_buf [ UDTSWAP_LIQUIDITY_UDT_ARGS_TX_INPUT_START ] ; if ( memcmp ( udtswap_liquidity_udt_code_hash_buf , script_code_hash_buf , CODE_HASH_SIZE ) != 0 ) { return CODE_HASH_NOT_MATCH_ERROR ; } uint8_t script_buf2 [ UDTSWAP_TYPE_SCRIPT_SIZE ] ; uint8_t * script_args_tx_input_buf2 ; len = UDTSWAP_TYPE_SCRIPT_SIZE ; ret = ckb_load_cell_by_field ( script_buf2 , & len , 0 , UDTSWAP_TYPE_CELL_INDEX , CKB_SOURCE_INPUT , CKB_CELL_FIELD_TYPE ) ; if ( ret != CKB_SUCCESS ) { return UDTSWAP_SYSCALL_ERROR - ret ; } if ( len != UDTSWAP_TYPE_SCRIPT_SIZE ) { return UDTSWAP_TYPE_SCRIPT_SIZE_NOT_CORRECT_ERROR ; } script_args_tx_input_buf2 = & script_buf2 [ ARGS_START ] ; if ( memcmp ( script_args_tx_input_buf , script_args_tx_input_buf2 , TX_INPUT_SIZE ) != 0 ) { return TX_INPUT_NOT_MATCH_ERROR ; } uint8_t script_hash_buf [ SCRIPT_HASH_SIZE ] ; len = SCRIPT_HASH_SIZE ; ret = ckb_load_cell_by_field ( script_hash_buf , & len , 0 , UDTSWAP_TYPE_CELL_INDEX , CKB_SOURCE_INPUT , CKB_CELL_FIELD_LOCK_HASH ) ; if ( ret != CKB_SUCCESS ) { return UDTSWAP_SYSCALL_ERROR - ret ; } if ( len != SCRIPT_HASH_SIZE ) { return SCRIPT_HASH_SIZE_NOT_CORRECT_ERROR ; } if ( memcmp ( script_hash_buf , script_args_lock_hash_buf , SCRIPT_HASH_SIZE ) != 0 ) { return SCRIPT_NOT_MATCH_ERROR ; } return CKB_SUCCESS ; }
@dev check UDTswap liquidity udt script
 check tx input
 check lock script hash (owner mode)
@dev check UDTswap liquidity udt script check tx input check lock script hash ( owner mode )
//udtswap liquidity udt code hash checked //udtswap tx input and udtswap liquidity udt tx input same checked //udtswap lock hash and udtswap liquidity owner lock same checked