SHARE
TWEET

Untitled

a guest Jun 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. create or replace procedure w2wtransfer(source varchar, destination varchar, amount int8,
  2.                                         description varchar(255), INOUT txid varchar) AS
  3. $$
  4. DECLARE
  5.     sourceWallet      RECORD;
  6.     destinationWallet RECORD;
  7. BEGIN
  8.     -- Query the source wallet
  9.     SELECT * into sourceWallet FROM wallets WHERE pan = source;
  10.     if not FOUND then
  11.         RAISE EXCEPTION 'Invalid source wallet provided: %', source USING HINT = '9000';
  12.     end if;
  13.  
  14.     -- Query the destination wallet
  15.     SELECT * into destinationWallet FROM wallets WHERE pan = destination;
  16.     if not FOUND then
  17.         RAISE EXCEPTION 'Invalid destination wallet provided: %', destination USING HINT = '9001';
  18.     end if;
  19.  
  20.     if sourceWallet.balance < amount then
  21.         RAISE EXCEPTION 'Source wallet has insufficient funds: %', source USING HINT = '8000';
  22.     end if;
  23.  
  24.     txid = concat(sourceWallet.pan, ' (', sourceWallet.balance, ')');
  25. END;
  26. $$ LANGUAGE plpgsql;
  27.  
  28.  
  29.  
  30. create or replace function transfer(source varchar, destination varchar, amount int8, description varchar) returns varchar
  31.     LANGUAGE plpgsql
  32. AS
  33. $$
  34. DECLARE
  35.     txid varchar;
  36. BEGIN
  37.     CALL w2wtransfer(source, destination, amount, destination, txid);
  38.     return txid;
  39. END
  40. $$;
  41.  
  42. SELECT transfer('RPS427470342427770', 'RPS188070575873036', 500, 'This is a test');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top