ether-pudding
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -9,6 +9,8 @@ (function() { | ||
Pudding.whisk = function(abi, defaults) { | ||
Pudding.global_defaults = {}; | ||
Pudding.recipe = function(abi, class_defaults) { | ||
var contract; | ||
contract = web3.eth.contract(abi); | ||
contract = Pudding.inject_transaction_defaults(contract, defaults); | ||
contract = Pudding.inject_defaults(contract, class_defaults); | ||
contract = Pudding.synchronize_contract(contract); | ||
@@ -21,11 +23,37 @@ if (Promise != null) { | ||
Pudding.inject_transaction_defaults = function(contract_class, defaults) { | ||
Pudding.defaults = function(new_global_defaults) { | ||
var i, key, len, value; | ||
if (new_global_defaults == null) { | ||
new_global_defaults = {}; | ||
} | ||
for (value = i = 0, len = new_global_defaults.length; i < len; value = ++i) { | ||
key = new_global_defaults[value]; | ||
this.global_defaults[key] = value; | ||
} | ||
return this.global_defaults; | ||
}; | ||
Pudding.inject_defaults = function(contract_class, class_defaults) { | ||
var old_at; | ||
old_at = contract_class.at; | ||
contract_class.at = function(address) { | ||
var abi_object, fn, fn_name, i, instance, key, len, ref, value; | ||
contract_class.at = function(address, instance_defaults) { | ||
var abi_object, fn, fn_name, i, instance, key, len, merged_defaults, ref, ref1, value; | ||
instance = old_at.call(contract_class, address); | ||
ref = contract_class.abi; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
abi_object = ref[i]; | ||
merged_defaults = {}; | ||
ref = this.global_defaults; | ||
for (key in ref) { | ||
value = ref[key]; | ||
merged_defaults[key] = value; | ||
} | ||
for (key in class_defaults) { | ||
value = class_defaults[key]; | ||
merged_defaults[key] = value; | ||
} | ||
for (key in instance_defaults) { | ||
value = instance_defaults[key]; | ||
merged_defaults[key] = value; | ||
} | ||
ref1 = contract_class.abi; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
abi_object = ref1[i]; | ||
fn_name = abi_object.name; | ||
@@ -36,3 +64,3 @@ fn = instance[fn_name]; | ||
} | ||
instance[fn_name] = Pudding.inject_transaction_defaults_into_function(instance, fn, defaults); | ||
instance[fn_name] = Pudding.inject_defaults_into_function(instance, fn, merged_defaults); | ||
for (key in fn) { | ||
@@ -42,4 +70,4 @@ value = fn[key]; | ||
} | ||
instance[fn_name].sendTransaction = Pudding.inject_transaction_defaults_into_function(instance, fn.sendTransaction, defaults); | ||
instance[fn_name].call = Pudding.inject_transaction_defaults_into_function(instance, fn.call, defaults); | ||
instance[fn_name].sendTransaction = Pudding.inject_defaults_into_function(instance, fn.sendTransaction, merged_defaults); | ||
instance[fn_name].call = Pudding.inject_defaults_into_function(instance, fn.call, merged_defaults); | ||
} | ||
@@ -51,3 +79,3 @@ return instance; | ||
Pudding.inject_transaction_defaults_into_function = function(instance, fn, defaults) { | ||
Pudding.inject_defaults_into_function = function(instance, fn, merged_defaults) { | ||
return function() { | ||
@@ -58,4 +86,4 @@ var args, callback, key, old_options, options, value; | ||
options = {}; | ||
for (key in defaults) { | ||
value = defaults[key]; | ||
for (key in merged_defaults) { | ||
value = merged_defaults[key]; | ||
options[key] = value; | ||
@@ -62,0 +90,0 @@ } |
/*! ether-pudding 24-06-2015 */ | ||
(function(){var a;a=function(a,b){var c;return c=function(){function c(){}return c.whisk=function(d,e){var f;return f=b.eth.contract(d),f=c.inject_transaction_defaults(f,e),f=c.synchronize_contract(f),null!=a&&(f=c.promisify_contract(f)),f},c.inject_transaction_defaults=function(a,b){var d;return d=a.at,a.at=function(e){var f,g,h,i,j,k,l,m,n;for(j=d.call(a,e),m=a.abi,i=0,l=m.length;l>i;i++)if(f=m[i],h=f.name,g=j[h],null!=g){j[h]=c.inject_transaction_defaults_into_function(j,g,b);for(k in g)n=g[k],j[h][k]=n;j[h].sendTransaction=c.inject_transaction_defaults_into_function(j,g.sendTransaction,b),j[h].call=c.inject_transaction_defaults_into_function(j,g.call,b)}return j},a},c.inject_transaction_defaults_into_function=function(a,b,c){return function(){var d,e,f,g,h,i;d=Array.prototype.slice.call(arguments),e=d.pop(),h={};for(f in c)i=c[f],h[f]=i;if("object"==typeof d[d.length-1]){g=d.pop();for(f in g)i=g[f],h[f]=i}return d.push(h,e),b.apply(a,d)}},c.promisify_contract=function(b){var c;return c=b.at,b.at=function(d){var e,f,g,h,i;f=c.call(b,d);for(h in f)if(e=f[h],"object"==typeof e||"function"==typeof e){for(g in e)i=e[g],("object"==typeof e||"function"==typeof e)&&(e[g]=a.promisify(i,f));f[h]=a.promisify(e,f)}return f},b},c.synchronize_function=function(a,c){var d,e,f;return e=null,f=240,d=0,function(){var g,h,i;return g=Array.prototype.slice.call(arguments),h=g.pop(),i=function(a,c){var g,i;return null!=a?void h(a,c):(i=c,e=null,g=function(){return b.eth.getTransaction(i,function(a,b){return null==a?(null!=b.blockHash&&(clearInterval(e),h(null,i)),d>=f&&(clearInterval(e),h("Transaction "+i+" wasn't processed in "+d+" attempts!",i)),d+=1):void 0})},e=setInterval(g,1e3),g())},g.push(i),c.apply(a,g)}},c.synchronize_contract=function(a){var b;return b=a.at,a.at=function(d){var e,f,g,h,i,j,k,l,m;for(i=b.call(a,d),l=a.abi,h=0,k=l.length;k>h;h++)if(e=l[h],g=e.name,f=i[g],null!=f){i[g]=c.synchronize_function(i,f);for(j in f)m=f[j],i[g][j]=m}return i},a},c}()},"undefined"!=typeof module&&null!==module&&null!=module.exports?module.exports=a(require("bluebird"),require("web3")):window.Pudding=a(Promise,web3)}).call(this); | ||
(function(){var a;a=function(a,b){var c;return c=function(){function c(){}return c.global_defaults={},c.recipe=function(d,e){var f;return f=b.eth.contract(d),f=c.inject_defaults(f,e),f=c.synchronize_contract(f),null!=a&&(f=c.promisify_contract(f)),f},c.defaults=function(a){var b,c,d,e;for(null==a&&(a={}),e=b=0,d=a.length;d>b;e=++b)c=a[e],this.global_defaults[c]=e;return this.global_defaults},c.inject_defaults=function(a,b){var d;return d=a.at,a.at=function(e,f){var g,h,i,j,k,l,m,n,o,p,q;k=d.call(a,e),n={},o=this.global_defaults;for(l in o)q=o[l],n[l]=q;for(l in b)q=b[l],n[l]=q;for(l in f)q=f[l],n[l]=q;for(p=a.abi,j=0,m=p.length;m>j;j++)if(g=p[j],i=g.name,h=k[i],null!=h){k[i]=c.inject_defaults_into_function(k,h,n);for(l in h)q=h[l],k[i][l]=q;k[i].sendTransaction=c.inject_defaults_into_function(k,h.sendTransaction,n),k[i].call=c.inject_defaults_into_function(k,h.call,n)}return k},a},c.inject_defaults_into_function=function(a,b,c){return function(){var d,e,f,g,h,i;d=Array.prototype.slice.call(arguments),e=d.pop(),h={};for(f in c)i=c[f],h[f]=i;if("object"==typeof d[d.length-1]){g=d.pop();for(f in g)i=g[f],h[f]=i}return d.push(h,e),b.apply(a,d)}},c.promisify_contract=function(b){var c;return c=b.at,b.at=function(d){var e,f,g,h,i;f=c.call(b,d);for(h in f)if(e=f[h],"object"==typeof e||"function"==typeof e){for(g in e)i=e[g],("object"==typeof e||"function"==typeof e)&&(e[g]=a.promisify(i,f));f[h]=a.promisify(e,f)}return f},b},c.synchronize_function=function(a,c){var d,e,f;return e=null,f=240,d=0,function(){var g,h,i;return g=Array.prototype.slice.call(arguments),h=g.pop(),i=function(a,c){var g,i;return null!=a?void h(a,c):(i=c,e=null,g=function(){return b.eth.getTransaction(i,function(a,b){return null==a?(null!=b.blockHash&&(clearInterval(e),h(null,i)),d>=f&&(clearInterval(e),h("Transaction "+i+" wasn't processed in "+d+" attempts!",i)),d+=1):void 0})},e=setInterval(g,1e3),g())},g.push(i),c.apply(a,g)}},c.synchronize_contract=function(a){var b;return b=a.at,a.at=function(d){var e,f,g,h,i,j,k,l,m;for(i=b.call(a,d),l=a.abi,h=0,k=l.length;k>h;h++)if(e=l[h],g=e.name,f=i[g],null!=f){i[g]=c.synchronize_function(i,f);for(j in f)m=f[j],i[g][j]=m}return i},a},c}()},"undefined"!=typeof module&&null!==module&&null!=module.exports?module.exports=a(require("bluebird"),require("web3")):window.Pudding=a(Promise,web3)}).call(this); |
{ | ||
"name": "ether-pudding", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Pudding - a (more) delightful Ethereum contract abstraction", | ||
@@ -5,0 +5,0 @@ "author": "Tim Coulter", |
@@ -40,3 +40,3 @@ # The Proof is in the Pudding | ||
MyContract = Pudding.whisk(abi) # You need to provide abi | ||
MyContract = Pudding.recipe(abi) # You need to provide abi | ||
``` | ||
@@ -47,3 +47,3 @@ | ||
```coffeescript | ||
MetaCoin = Pudding.whisk(metaCoinABI) | ||
MetaCoin = Pudding.recipe(metaCoinABI) | ||
@@ -86,2 +86,6 @@ # In this scenario, two users will send MetaCoin back and forth, showing | ||
### More Examples | ||
* [Setting global, contract-level and instance-level defaults](/ConsenSys/ether-pudding/wiki/Setting-global,-contract-level-and-instance-level-defaults) | ||
### Building | ||
@@ -88,0 +92,0 @@ |
Sorry, the diff of this file is not supported yet
22321
188
100